Skip to content

Commit

Permalink
fix(browser): multi-suite coverage (#3806)
Browse files Browse the repository at this point in the history
  • Loading branch information
elby22 committed Jul 31, 2023
1 parent dc4faf6 commit 5de9af2
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/browser/src/client/runner.ts
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
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
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
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
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
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
@@ -0,0 +1,9 @@
export default {
func1(data: any[]) {
return data
},

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

0 comments on commit 5de9af2

Please sign in to comment.