Skip to content
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(smoke): check runner result is sensible before using #14343

Merged
merged 3 commits into from
Sep 7, 2022

Conversation

connorjclark
Copy link
Collaborator

Once #14320 landed I then saw another error further down the report assertion function. So let's fix the root cause: we shouldn't just trust that lighthouseRunner returns a valid LH.Result. At least for the CLI runner, it's possible an error occurred (ex: config resolution failed) resulting in no LHR at all (just an empty object being returned. or maybe it was undefined).

@connorjclark connorjclark requested a review from a team as a code owner September 1, 2022 19:16
@connorjclark connorjclark requested review from brendankenny and removed request for a team September 1, 2022 19:16
@brendankenny
Copy link
Member

I believe the intention was lighthouseRunner would either return a Promise<{lhr: LHResult, artifacts: Artifacts, log: string}> or throw an error. In the error case the catch will catch it and continue to the end of the loop, never running the assertions (stderr should be logged and the whole test counted as a failure).

Is the problem that the non-CLI versions are returning something in the error cases instead? The CLI has this check basically built in because it loads the LHR and artifacts from disk, so will throw if they're not around:

try {
await fs.access(outputPath);
} catch (e) {
throw new ChildProcessError(`Lighthouse run failed to produce a report and exited with ${exitCode}.`, // eslint-disable-line max-len
localConsole.getLog());
}
/** @type {LH.Result} */
const lhr = JSON.parse(await fs.readFile(outputPath, 'utf8'));
const artifacts = assetSaver.loadArtifacts(artifactsDirectory);

Can we do the same in bundle/devtools?

We could loosen the types for lighthouseRunner instead, but bundle already does a third of the check here, and devtools is writing possibly nonsense to disk here, so it seems like a benefit. In theory the check can grow to runner-specific checks like cli does as well (like checking that if there's a non-zero exit code there was also a lhr.runtimeError in the expectations), so e.g. devtools could log more specific errors due to build issues or pptr setup or whatever.

Co-authored-by: Brendan Kenny <bckenny@gmail.com>
@paulirish
Copy link
Member

mkay

@connorjclark connorjclark merged commit b56c7b9 into master Sep 7, 2022
@connorjclark connorjclark deleted the smoke-check-result branch September 7, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants