Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright/src/reporters/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function lcovReport(mergedJson: IstanbulCoverage): string {
const counts: number[] = fileCov.b[key] || [];
branch.locations.forEach((location, i) => {
const count = counts[i] || 0;
out.push(`BRDA:${location.start.line ?? branch.loc.start.line},${key},${i},${count}`);
out.push(`BRDA:${location.start?.line ?? branch.loc?.start?.line ?? branch.line ?? 0},${key},${i},${count}`);
++branchesFound;
if (count > 0)
++branchesCovered;
Expand Down
13 changes: 10 additions & 3 deletions tests/playwright-test/coverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ const coverageHelper = `
'0': { name: 'foo', decl: { start: { line: 1, column: 0 }, end: { line: 1, column: 3 } }, loc: { start: { line: 1, column: 0 }, end: { line: 3, column: 1 } }, line: 1 },
},
branchMap: {
'0': { loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 20 } }, type: 'if', locations: [{ start: { line: 2, column: 0 }, end: { line: 2, column: 10 } }, { start: { line: 2, column: 10 }, end: { line: 2, column: 20 } }], line: 2 },
'0': { loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 20 } }, type: 'if', locations: [{ start: { line: 2, column: 0 }, end: { line: 2, column: 10 } }, {} as any], line: 2 },
'1': { type: 'if', locations: [{} as any], line: 3 },
},
s: { '0': s0, '1': 0 },
f: { '0': 1 },
b: { '0': [1, 0] },
b: { '0': [1, 0], '1': [1] },
},
});
const coverageScript = (file, s0) => '<script>window.__coverage__ = ' + JSON.stringify(makeCoverage(file, s0)) + '</script>';
Expand Down Expand Up @@ -79,10 +80,13 @@ test('should collect istanbul coverage into the trace', async ({ runInlineTest }
expect(data['src/app.js'].s['1']).toBe(0);
expect(data['src/app.js'].f['0']).toBe(2);
expect(data['src/app.js'].b['0']).toEqual([2, 0]);
expect(data['src/app.js'].b['1']).toEqual([2]);
expect(data['src/frame.js'].s['0']).toBe(3);
});

test('should aggregate coverage with the coverage reporter', async ({ runInlineTest }) => {
test('should aggregate coverage with the coverage reporter', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/44113' },
}, async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
export default {
Expand Down Expand Up @@ -117,12 +121,15 @@ test('should aggregate coverage with the coverage reporter', async ({ runInlineT
expect(final['src/app.js'].s['1']).toBe(0);
expect(final['src/app.js'].f['0']).toBe(2);
expect(final['src/app.js'].b['0']).toEqual([2, 0]);
expect(final['src/app.js'].b['1']).toEqual([2]);
expect(final['src/second.js'].s['0']).toBe(4);

const lcov = fs.readFileSync(test.info().outputPath('coverage-report', 'lcov.info'), 'utf8');
expect(lcov).toContain('SF:src/app.js');
expect(lcov).toContain('DA:1,7');
expect(lcov).toContain('FNDA:2,foo');
expect(lcov).toContain('BRDA:2,0,1,0');
expect(lcov).toContain('BRDA:3,1,0,2');
expect(lcov).toContain('SF:src/second.js');

expect(result.output).toContain('Code coverage (2 files)');
Expand Down
Loading