-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
tests(smokehouse): always assert lhr.runtimeError #9130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,10 @@ module.exports = [ | |
// Note: most scores are null (audit error) because the page 403ed. | ||
requestedUrl: BASE_URL + 'seo-failure-cases.html?status_code=403', | ||
finalUrl: BASE_URL + 'seo-failure-cases.html?status_code=403', | ||
runtimeError: { | ||
code: 'ERRORED_DOCUMENT_REQUEST', | ||
message: /Status code: 403/, | ||
}, | ||
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. has to be asserted now |
||
audits: { | ||
'http-status-code': { | ||
score: 0, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,11 @@ function makeComparison(name, actualResult, expectedResult) { | |
* @return {Smokehouse.Comparison[]} | ||
*/ | ||
function collateResults(actual, expected) { | ||
// If actual run had a runtimeError, expected *must* have a runtimeError. | ||
// Relies on the fact that an `undefined` argument to makeComparison() can only match `undefined`. | ||
const runtimeErrorAssertion = makeComparison('runtimeError', actual.lhr.runtimeError, | ||
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. doh! everything is off of 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.
agreed, though I really want to make sure we check |
||
expected.lhr.runtimeError); | ||
|
||
/** @type {Smokehouse.Comparison[]} */ | ||
let artifactAssertions = []; | ||
if (expected.artifacts) { | ||
|
@@ -161,6 +166,7 @@ function collateResults(actual, expected) { | |
expected: expected.lhr.finalUrl, | ||
equal: actual.lhr.finalUrl === expected.lhr.finalUrl, | ||
}, | ||
runtimeErrorAssertion, | ||
...artifactAssertions, | ||
...auditAssertions, | ||
]; | ||
|
@@ -194,7 +200,8 @@ function reportAssertion(assertion) { | |
} else { | ||
if (assertion.diff) { | ||
const diff = assertion.diff; | ||
const fullActual = JSON.stringify(assertion.actual, null, 2).replace(/\n/g, '\n '); | ||
const fullActual = String(JSON.stringify(assertion.actual, null, 2)) | ||
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. fixes the case when |
||
.replace(/\n/g, '\n '); | ||
const msg = ` | ||
${log.redify(log.cross)} difference at ${log.bold}${diff.path}${log.reset} | ||
expected: ${JSON.stringify(diff.expected)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,10 @@ const path = require('path'); | |
const spawnSync = require('child_process').spawnSync; | ||
const yargs = require('yargs'); | ||
const log = require('lighthouse-logger'); | ||
const rimraf = require('rimraf'); | ||
|
||
const {collateResults, report} = require('./smokehouse-report.js'); | ||
const assetSaver = require('../../../lighthouse-core/lib/asset-saver.js'); | ||
|
||
const PROTOCOL_TIMEOUT_EXIT_CODE = 67; | ||
const RETRIES = 3; | ||
|
@@ -88,27 +91,34 @@ function runLighthouse(url, configPath, isDebug) { | |
console.error(`STDERR: ${runResults.stderr}`); | ||
} | ||
|
||
if (runResults.status === PROTOCOL_TIMEOUT_EXIT_CODE) { | ||
const exitCode = runResults.status; | ||
if (exitCode === PROTOCOL_TIMEOUT_EXIT_CODE) { | ||
console.error(`Lighthouse debugger connection timed out ${RETRIES} times. Giving up.`); | ||
process.exit(1); | ||
} else if (!fs.existsSync(outputPath)) { | ||
console.error(`Lighthouse run failed to produce a report and exited with ${runResults.status}. stderr to follow:`); // eslint-disable-line max-len | ||
console.error(`Lighthouse run failed to produce a report and exited with ${exitCode}. stderr to follow:`); // eslint-disable-line max-len | ||
console.error(runResults.stderr); | ||
process.exit(runResults.status); | ||
process.exit(exitCode); | ||
} | ||
|
||
/** @type {LH.Result} */ | ||
const lhr = JSON.parse(fs.readFileSync(outputPath, 'utf8')); | ||
const artifacts = assetSaver.loadArtifacts(artifactsDirectory); | ||
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. we weren't loading the trace(s) and devtoolsLogs before, and I guess it's possible someone will want them at some point :) Regardless, switching to |
||
|
||
if (isDebug) { | ||
console.log('LHR output available at: ', outputPath); | ||
console.log('Artifacts avaiable in: ', artifactsDirectory); | ||
} else { | ||
fs.unlinkSync(outputPath); | ||
rimraf.sync(artifactsDirectory); | ||
} | ||
|
||
// Artifacts are undefined if they weren't written to disk (e.g. if there was an error). | ||
let artifacts; | ||
try { | ||
artifacts = JSON.parse(fs.readFileSync(`${artifactsDirectory}/artifacts.json`, 'utf8')); | ||
} catch (e) {} | ||
// There should either be both an error exitCode and a lhr.runtimeError or neither. | ||
if (Boolean(exitCode) !== Boolean(lhr.runtimeError)) { | ||
const runtimeErrorCode = lhr.runtimeError && lhr.runtimeError.code; | ||
console.error(`Lighthouse did not exit with an error correctly, exiting with ${exitCode} but with runtimeError '${runtimeErrorCode}'`); // eslint-disable-line max-len | ||
process.exit(1); | ||
} | ||
|
||
return { | ||
lhr, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,9 @@ const devtoolsLogSuffix = '.devtoolslog.json'; | |
* Load artifacts object from files located within basePath | ||
* Also save the traces to their own files | ||
* @param {string} basePath | ||
* @return {Promise<LH.Artifacts>} | ||
* @return {LH.Artifacts} | ||
*/ | ||
async function loadArtifacts(basePath) { | ||
function loadArtifacts(basePath) { | ||
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. fix to keep smokehouse's 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.
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.
ha, fair. Nothing is async in it anyways, though, so saves us a microtask or two :) |
||
log.log('Reading artifacts from disk:', basePath); | ||
|
||
if (!fs.existsSync(basePath)) { | ||
|
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.
heh, yikes I forgot about that!