-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(css-usage): fetch stylesheet contents immediately after discovery (
- Loading branch information
Showing
8 changed files
with
145 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
lighthouse-core/test/fixtures/fraggle-rock/css-change/end.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
border: 5px solid red; | ||
} |
13 changes: 13 additions & 0 deletions
13
lighthouse-core/test/fixtures/fraggle-rock/css-change/end.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="/end.css"> | ||
</head> | ||
<body> | ||
<style>h1 {color: red}</style> | ||
<h1>Should have different styles than the start page</h1> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
lighthouse-core/test/fixtures/fraggle-rock/css-change/start.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
border: 5px solid black; | ||
} |
15 changes: 15 additions & 0 deletions
15
lighthouse-core/test/fixtures/fraggle-rock/css-change/start.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="/start.css"> | ||
</head> | ||
<body> | ||
<style>h1 {color: gray}</style> | ||
<h1>Start page</h1> | ||
<h2>Stylesheets should change after navigating to the next page</h2> | ||
<a href="/end.html">Next</a> | ||
</body> | ||
</html> |
40 changes: 40 additions & 0 deletions
40
lighthouse-core/test/fraggle-rock/scenarios/cross-origin-test-pptr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {jest} from '@jest/globals'; | ||
|
||
import * as lighthouse from '../../../fraggle-rock/api.js'; | ||
import {createTestState} from './pptr-test-utils.js'; | ||
import {LH_ROOT} from '../../../../root.js'; | ||
|
||
/* eslint-env jest */ | ||
/* eslint-env browser */ | ||
|
||
jest.setTimeout(90_000); | ||
|
||
describe('Cross origin timespan', () => { | ||
const state = createTestState(); | ||
|
||
state.installSetupAndTeardownHooks(); | ||
|
||
beforeAll(() => { | ||
state.server.baseDir = state.secondaryServer.baseDir = | ||
`${LH_ROOT}/lighthouse-core/test/fixtures/fraggle-rock/css-change`; | ||
}); | ||
|
||
it('should resolve all stylesheets', async () => { | ||
await state.page.goto(`${state.serverBaseUrl}/start.html`, {waitUntil: ['networkidle0']}); | ||
|
||
const timespan = await lighthouse.startTimespan({page: state.page}); | ||
await state.page.goto(`${state.secondaryServerBaseUrl}/end.html`); | ||
const result = await timespan.endTimespan(); | ||
if (!result) throw new Error('Lighthouse did not return a result'); | ||
|
||
// Ensure CSS usage didn't error. | ||
expect(result.artifacts.CSSUsage.stylesheets).toHaveLength(4); | ||
expect(result.lhr.audits['unused-css-rules'].score).not.toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters