Skip to content

Commit

Permalink
fix: CSS coverage should work with empty stylesheets (#8570)
Browse files Browse the repository at this point in the history
Closes #8535
  • Loading branch information
OrKoN committed Jun 24, 2022
1 parent 5e6b93f commit 383e855
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/common/Coverage.ts
Expand Up @@ -407,9 +407,15 @@ export class CSSCoverage {
const coverage: CoverageEntry[] = [];
for (const styleSheetId of this.#stylesheetURLs.keys()) {
const url = this.#stylesheetURLs.get(styleSheetId);
assert(url);
assert(
typeof url !== 'undefined',
`Stylesheet URL is undefined (styleSheetId=${styleSheetId})`
);
const text = this.#stylesheetSources.get(styleSheetId);
assert(text);
assert(
typeof text !== 'undefined',
`Stylesheet text is undefined (styleSheetId=${styleSheetId})`
);
const ranges = convertToDisjointRanges(
styleSheetIdToCoverage.get(styleSheetId) || []
);
Expand Down
3 changes: 3 additions & 0 deletions test/assets/csscoverage/empty.html
@@ -0,0 +1,3 @@
<style></style>
<div>empty style tag</div>

9 changes: 9 additions & 0 deletions test/src/coverage.spec.ts
Expand Up @@ -270,6 +270,15 @@ describe('Coverage specs', function () {
JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':<PORT>/')
).toBeGolden('csscoverage-involved.txt');
});
it('should work with empty stylesheets', async () => {
const {page, server} = getTestState();

await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/empty.html');
const coverage = await page.coverage.stopCSSCoverage();
expect(coverage.length).toEqual(1);
expect(coverage[0]!.text).toEqual('');
});
it('should ignore injected stylesheets', async () => {
const {page} = getTestState();

Expand Down

0 comments on commit 383e855

Please sign in to comment.