diff --git a/src/common/Coverage.ts b/src/common/Coverage.ts index c7be817a..3a06d874 100644 --- a/src/common/Coverage.ts +++ b/src/common/Coverage.ts @@ -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) || [] ); diff --git a/test/assets/csscoverage/empty.html b/test/assets/csscoverage/empty.html new file mode 100644 index 00000000..b3845c36 --- /dev/null +++ b/test/assets/csscoverage/empty.html @@ -0,0 +1,3 @@ + +
empty style tag
+ diff --git a/test/src/coverage.spec.ts b/test/src/coverage.spec.ts index 41eb0890..9da30fb7 100644 --- a/test/src/coverage.spec.ts +++ b/test/src/coverage.spec.ts @@ -270,6 +270,15 @@ describe('Coverage specs', function () { JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':/') ).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();