Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser): multi-suite coverage #3806

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/browser/src/client/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function createBrowserRunner(original: any, coverageModule: CoverageHandl
}
}

async onAfterRunSuite() {
await super.onAfterRunSuite?.()
async onAfterRun() {
await super.onAfterRun?.()
const coverage = await coverageModule?.takeCoverage?.()
await rpc().onAfterSuiteRun({ coverage })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports[`custom json report 1`] = `
"<process-cwd>/src/implicitElse.ts",
"<process-cwd>/src/importEnv.ts",
"<process-cwd>/src/index.mts",
"<process-cwd>/src/multi-suite.ts",
"<process-cwd>/src/utils.ts",
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,89 @@ exports[`istanbul json report 1`] = `
},
},
},
"<process-cwd>/src/multi-suite.ts": {
"b": {},
"branchMap": {},
"f": {
"0": 1,
"1": 1,
},
"fnMap": {
"0": {
"decl": {
"end": {
"column": 8,
"line": 2,
},
"start": {
"column": 2,
"line": 2,
},
},
"loc": {
"end": {
"column": null,
"line": 4,
},
"start": {
"column": 21,
"line": 2,
},
},
"name": "(anonymous_0)",
},
"1": {
"decl": {
"end": {
"column": 8,
"line": 6,
},
"start": {
"column": 2,
"line": 6,
},
},
"loc": {
"end": {
"column": null,
"line": 8,
},
"start": {
"column": 21,
"line": 6,
},
},
"name": "(anonymous_1)",
},
},
"path": "<process-cwd>/src/multi-suite.ts",
"s": {
"0": 1,
"1": 1,
},
"statementMap": {
"0": {
"end": {
"column": null,
"line": 3,
},
"start": {
"column": 4,
"line": 3,
},
},
"1": {
"end": {
"column": null,
"line": 7,
},
"start": {
"column": 4,
"line": 7,
},
},
},
},
"<process-cwd>/src/untested-file.ts": {
"b": {
"0": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,229 @@ exports[`v8 json report 1`] = `
},
},
},
"<process-cwd>/src/multi-suite.ts": {
"all": false,
"b": {
"0": [
1,
],
"1": [
1,
],
},
"branchMap": {
"0": {
"line": 2,
"loc": {
"end": {
"column": 4,
"line": 4,
},
"start": {
"column": 2,
"line": 2,
},
},
"locations": [
{
"end": {
"column": 4,
"line": 4,
},
"start": {
"column": 2,
"line": 2,
},
},
],
"type": "branch",
},
"1": {
"line": 6,
"loc": {
"end": {
"column": 4,
"line": 8,
},
"start": {
"column": 2,
"line": 6,
},
},
"locations": [
{
"end": {
"column": 4,
"line": 8,
},
"start": {
"column": 2,
"line": 6,
},
},
],
"type": "branch",
},
},
"f": {
"0": 1,
"1": 1,
},
"fnMap": {
"0": {
"decl": {
"end": {
"column": 4,
"line": 4,
},
"start": {
"column": 2,
"line": 2,
},
},
"line": 2,
"loc": {
"end": {
"column": 4,
"line": 4,
},
"start": {
"column": 2,
"line": 2,
},
},
"name": "func1",
},
"1": {
"decl": {
"end": {
"column": 4,
"line": 8,
},
"start": {
"column": 2,
"line": 6,
},
},
"line": 6,
"loc": {
"end": {
"column": 4,
"line": 8,
},
"start": {
"column": 2,
"line": 6,
},
},
"name": "func2",
},
},
"path": "<process-cwd>/src/multi-suite.ts",
"s": {
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 1,
"8": 1,
},
"statementMap": {
"0": {
"end": {
"column": 16,
"line": 1,
},
"start": {
"column": 0,
"line": 1,
},
},
"1": {
"end": {
"column": 22,
"line": 2,
},
"start": {
"column": 0,
"line": 2,
},
},
"2": {
"end": {
"column": 15,
"line": 3,
},
"start": {
"column": 0,
"line": 3,
},
},
"3": {
"end": {
"column": 4,
"line": 4,
},
"start": {
"column": 0,
"line": 4,
},
},
"4": {
"end": {
"column": 0,
"line": 5,
},
"start": {
"column": 0,
"line": 5,
},
},
"5": {
"end": {
"column": 22,
"line": 6,
},
"start": {
"column": 0,
"line": 6,
},
},
"6": {
"end": {
"column": 15,
"line": 7,
},
"start": {
"column": 0,
"line": 7,
},
},
"7": {
"end": {
"column": 4,
"line": 8,
},
"start": {
"column": 0,
"line": 8,
},
},
"8": {
"end": {
"column": 1,
"line": 9,
},
"start": {
"column": 0,
"line": 9,
},
},
},
},
"<process-cwd>/src/untested-file.ts": {
"all": true,
"b": {
Expand Down
13 changes: 13 additions & 0 deletions test/coverage-test/coverage-report-tests/istanbul.report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ test('ignored code is excluded from the report', async () => {
const utils = await import('../src/utils')
expect(utils[functionName]).toBeTypeOf('function')
})

test('tests with multiple suites are covered', async () => {
const coverageMap = await readCoverageJson()

const filename = '<process-cwd>/src/multi-suite.ts'
const fileCoverage = coverageMap[filename]

// Assert that all functions are covered
expect(fileCoverage.f).toMatchObject({
0: 1,
1: 1,
})
})
13 changes: 13 additions & 0 deletions test/coverage-test/coverage-report-tests/v8.report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ test('ignored code is marked as covered in the report', async () => {
const utils = await import('../src/utils')
expect(utils[functionName]).toBeTypeOf('function')
})

test('tests with multiple suites are covered', async () => {
const coverageMap = await readCoverageJson()

const filename = '<process-cwd>/src/multi-suite.ts'
const fileCoverage = coverageMap[filename]

// Assert that all functions are covered
expect(fileCoverage.f).toMatchObject({
0: 1,
1: 1,
})
})
9 changes: 9 additions & 0 deletions test/coverage-test/src/multi-suite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
func1(data: any[]) {
return data
},

func2(data: any[]) {
return data
},
}