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

core: remove NO_ERROR from default responses #7358

Merged
merged 5 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lighthouse-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/
'use strict';

require('./bin.js').begin().catch(err => {
require('./bin.js').begin().then((lhr) => {
// Exit with non-zero exit code if LHR contains runtime error.
if (lhr && lhr.lhr.runtimeError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we can handle this in run.js with the other runtime error/exiting code

process.exit(1);
}
}).catch(err => {
process.stderr.write(err.stack);
process.exit(1);
});
16 changes: 16 additions & 0 deletions lighthouse-cli/test/cli/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('CLI Tests', function() {
const config = JSON.parse(ret.stdout);
assert.strictEqual(config.settings.output[0], 'html');
assert.strictEqual(config.settings.auditMode, false);
assert.equal(ret.status, 0);

expect(config).toMatchSnapshot();
});
Expand All @@ -91,8 +92,23 @@ describe('CLI Tests', function() {
assert.strictEqual(config.settings.output[0], 'json');
assert.strictEqual(config.settings.auditMode, true);
assert.strictEqual(config.audits.length, 1);
assert.equal(ret.status, 0);

expect(config).toMatchSnapshot();
});
});

describe('non-zero exit codes', () => {
it('should exit with code 1 if the LHR contains an error', () => {
const flags = [
'chrome://error',
`--max-wait-for-load=${9000}`,
'--output-path=stdout',
];
const ret = spawnSync('node', [indexPath, ...flags], {encoding: 'utf8'});

// Exit with non-zero code.
assert.equal(ret.status, 1);
}, 20 * 1000);
});
});
7 changes: 2 additions & 5 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class Runner {
/**
* Returns first runtimeError found in artifacts.
* @param {LH.Artifacts} artifacts
* @return {LH.Result['runtimeError']}
* @return {LH.Result['runtimeError']|undefined}
*/
static getArtifactRuntimeError(artifacts) {
for (const possibleErrorArtifact of Object.values(artifacts)) {
Expand All @@ -345,10 +345,7 @@ class Runner {
}
}

return {
code: LHError.NO_ERROR,
message: '',
};
return undefined;
exterkamp marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
4 changes: 0 additions & 4 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"requestedUrl": "http://localhost:10200/dobetterweb/dbw_tester.html",
"finalUrl": "http://localhost:10200/dobetterweb/dbw_tester.html",
"runWarnings": [],
"runtimeError": {
"code": "NO_ERROR",
"message": ""
},
"audits": {
"is-on-https": {
"id": "is-on-https",
Expand Down
2 changes: 1 addition & 1 deletion types/lhr.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ declare global {
/** List of top-level warnings for this Lighthouse run. */
runWarnings: string[];
/** A top-level error message that, if present, indicates a serious enough problem that this Lighthouse result may need to be discarded. */
runtimeError: {code: string, message: string};
runtimeError?: {code: string, message: string};
/** The User-Agent string of the browser used run Lighthouse for these results. */
userAgent: string;
/** Information about the environment in which Lighthouse was run. */
Expand Down