fix: CSS coverage should work with empty stylesheets (#8570)
Closes #8535
This commit is contained in:
parent
5e6b93f7e3
commit
383e855847
@ -407,9 +407,15 @@ export class CSSCoverage {
|
|||||||
const coverage: CoverageEntry[] = [];
|
const coverage: CoverageEntry[] = [];
|
||||||
for (const styleSheetId of this.#stylesheetURLs.keys()) {
|
for (const styleSheetId of this.#stylesheetURLs.keys()) {
|
||||||
const url = this.#stylesheetURLs.get(styleSheetId);
|
const url = this.#stylesheetURLs.get(styleSheetId);
|
||||||
assert(url);
|
assert(
|
||||||
|
typeof url !== 'undefined',
|
||||||
|
`Stylesheet URL is undefined (styleSheetId=${styleSheetId})`
|
||||||
|
);
|
||||||
const text = this.#stylesheetSources.get(styleSheetId);
|
const text = this.#stylesheetSources.get(styleSheetId);
|
||||||
assert(text);
|
assert(
|
||||||
|
typeof text !== 'undefined',
|
||||||
|
`Stylesheet text is undefined (styleSheetId=${styleSheetId})`
|
||||||
|
);
|
||||||
const ranges = convertToDisjointRanges(
|
const ranges = convertToDisjointRanges(
|
||||||
styleSheetIdToCoverage.get(styleSheetId) || []
|
styleSheetIdToCoverage.get(styleSheetId) || []
|
||||||
);
|
);
|
||||||
|
3
test/assets/csscoverage/empty.html
Normal file
3
test/assets/csscoverage/empty.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<style></style>
|
||||||
|
<div>empty style tag</div>
|
||||||
|
|
@ -270,6 +270,15 @@ describe('Coverage specs', function () {
|
|||||||
JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':<PORT>/')
|
JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':<PORT>/')
|
||||||
).toBeGolden('csscoverage-involved.txt');
|
).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 () => {
|
it('should ignore injected stylesheets', async () => {
|
||||||
const {page} = getTestState();
|
const {page} = getTestState();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user