-
Notifications
You must be signed in to change notification settings - Fork 9.5k
report: fix compat for older lighthouse reports #14617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ describe('Lighthouse Viewer', () => { | |
let browser; | ||
/** @type {import('puppeteer').Page} */ | ||
let viewerPage; | ||
const pageErrors = []; | ||
let pageErrors = []; | ||
|
||
const selectors = { | ||
audits: '.lh-audit, .lh-metric', | ||
|
@@ -69,16 +69,29 @@ describe('Lighthouse Viewer', () => { | |
}); | ||
|
||
after(async function() { | ||
// Log any page load errors encountered in case before() failed. | ||
// eslint-disable-next-line no-console | ||
if (pageErrors.length > 0) console.error(pageErrors); | ||
|
||
await Promise.all([ | ||
server.close(), | ||
browser && browser.close(), | ||
]); | ||
}); | ||
|
||
beforeEach(async function() { | ||
pageErrors = []; | ||
}); | ||
|
||
async function ensureNoErrors() { | ||
await viewerPage.evaluate(() => new Promise(window.requestAnimationFrame)); | ||
const theErrors = pageErrors; | ||
pageErrors = []; | ||
expect(theErrors).toHaveLength(0); | ||
} | ||
|
||
afterEach(async function() { | ||
// Tests should call this themselves so the failure is associated with them in the test report, | ||
// but just in case one is missed it won't hurt to repeat the check here. | ||
await ensureNoErrors(); | ||
}); | ||
|
||
describe('Renders the flow report', () => { | ||
before(async () => { | ||
await viewerPage.goto(viewerUrl, {waitUntil: 'networkidle2', timeout: 30000}); | ||
|
@@ -88,7 +101,7 @@ describe('Lighthouse Viewer', () => { | |
}); | ||
|
||
it('should load with no errors', async () => { | ||
assert.deepStrictEqual(pageErrors, []); | ||
await ensureNoErrors(); | ||
}); | ||
|
||
it('renders the summary page', async () => { | ||
|
@@ -100,7 +113,7 @@ describe('Lighthouse Viewer', () => { | |
); | ||
assert.equal(scores.length, 14); | ||
|
||
assert.deepStrictEqual(pageErrors, []); | ||
await ensureNoErrors(); | ||
}); | ||
}); | ||
|
||
|
@@ -113,7 +126,7 @@ describe('Lighthouse Viewer', () => { | |
}); | ||
|
||
it('should load with no errors', async () => { | ||
assert.deepStrictEqual(pageErrors, []); | ||
await ensureNoErrors(); | ||
}); | ||
|
||
it('should contain all categories', async () => { | ||
|
@@ -251,6 +264,30 @@ describe('Lighthouse Viewer', () => { | |
}); | ||
}); | ||
|
||
describe('Renders old reports', () => { | ||
[ | ||
'lhr-3.0.0.json', | ||
'lhr-4.3.0.json', | ||
'lhr-5.0.0.json', | ||
'lhr-6.0.0.json', | ||
'lhr-8.5.0.json', | ||
].forEach((testFilename) => { | ||
it(`[${testFilename}] should load with no errors`, async () => { | ||
await viewerPage.goto(viewerUrl, {waitUntil: 'networkidle2', timeout: 30000}); | ||
const fileInput = await viewerPage.$('#hidden-file-input'); | ||
const waitForAck = viewerPage.evaluate(() => | ||
new Promise(resolve => | ||
document.addEventListener('lh-file-upload-test-ack', resolve, {once: true}))); | ||
await fileInput.uploadFile(`${LH_ROOT}/report/test-assets/${testFilename}`); | ||
Comment on lines
+278
to
+281
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this promise structure guarantees that the event listener is installed by the time we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Protocol commands are executed in sequence, so why wouldn't this be alright? the callback inside the promise is a microtask, but I think even then it runs on the main thread and so would any commands called by fileInput.upload so should be all good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Interesting, did not know this. This is probably fine then. |
||
await Promise.race([ | ||
waitForAck, | ||
new Promise((resolve, reject) => setTimeout(reject, 5_000)), | ||
]); | ||
await ensureNoErrors(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('PSI', () => { | ||
/** @type {Partial<puppeteer.ResponseForRequest>} */ | ||
let interceptedRequest; | ||
|
@@ -351,7 +388,7 @@ describe('Lighthouse Viewer', () => { | |
expect(interceptedUrl.searchParams.getAll('category').sort()).toEqual(defaultCategories); | ||
|
||
// No errors. | ||
assert.deepStrictEqual(pageErrors, []); | ||
await ensureNoErrors(); | ||
|
||
// All categories. | ||
const categoryElementIds = await getCategoryElementsIds(); | ||
|
@@ -395,7 +432,7 @@ describe('Lighthouse Viewer', () => { | |
}); | ||
|
||
// No errors. | ||
assert.deepStrictEqual(pageErrors, []); | ||
await ensureNoErrors(); | ||
}); | ||
|
||
it('should handle errors from the API', async () => { | ||
|
@@ -412,6 +449,7 @@ describe('Lighthouse Viewer', () => { | |
// One error. | ||
expect(pageErrors).toHaveLength(1); | ||
expect(pageErrors[0].message).toContain('badPsiResponse error'); | ||
pageErrors = []; | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO for this PR or later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an optional, p100 thing :P just something I noticed and wanted to document in the relevant place.