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: partial artifact update #8802

Merged
merged 17 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ Don't:
If no reference doc exists yet, then you can use the `description` as a stopgap for explaining
both why the audit is important and how to fix it.

## Updating sample artifacts and LHR JSON

```
yarn run update:sample-artifacts # update all artifacts
yarn run update:sample-artifacts ScriptElements # update just one artifact
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
yarn run update:sample-json # update sample LHR based on sample artifacts
```

When updating all artifacts, usually you'll need to revert changes to the `*.devtoolslog.json` and `*.trace.json` files and manually review changes to `artifacts.json` to make sure they are related to your work.

## Tracking Errors

We track our errors in the wild with Sentry. In general, do not worry about wrapping your audits or gatherers in try/catch blocks and reporting every error that could possibly occur; `lighthouse-core/runner.js` and `lighthouse-core/gather/gather-runner.js` already catch and report any errors that occur while running a gatherer or audit, including errors fatal to the entire run. However, there are some situations when you might want to explicitly handle an error and report it to Sentry or wrap it to avoid reporting. Generally, you can interact with Sentry simply by requiring the `lighthouse-core/lib/sentry.js` file and call its methods. The module exports a delegate that will correctly handle the error reporting based on the user's opt-in preference and will simply no-op if they haven't so you don't need to check.
Expand Down
25 changes: 21 additions & 4 deletions lighthouse-core/scripts/update-report-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

const cli = require('../../lighthouse-cli/run.js');
const cliFlags = require('../../lighthouse-cli/cli-flags.js');
const assetSaver = require('../lib/asset-saver.js');

const artifactPath = 'lighthouse-core/test/results/artifacts';
paulirish marked this conversation as resolved.
Show resolved Hide resolved

const {server} = require('../../lighthouse-cli/test/fixtures/static-server.js');

Expand All @@ -32,9 +35,10 @@ const budgetedConfig = {
};

/**
* Update the report artifacts
* Update the report artifacts. If artifactName is set only that artifact will be updated.
* @param {keyof LH.Artifacts=} artifactName
*/
async function update() {
async function update(artifactName) {
// get an available port
server.listen(0, 'localhost');
const port = await new Promise(res => server.on('listening', () => {
Expand All @@ -43,15 +47,28 @@ async function update() {
res(address.port);
}));

const oldArtifacts = await assetSaver.loadArtifacts(artifactPath);

const url = `http://localhost:${port}/dobetterweb/dbw_tester.html`;
const rawFlags = [
'--gather-mode=lighthouse-core/test/results/artifacts',
`--gather-mode=${artifactPath}`,
'--throttling-method=devtools',
url,
].join(' ');
const flags = cliFlags.getFlags(rawFlags);
await cli.runLighthouse(url, flags, budgetedConfig);
await new Promise(res => server.close(res));

if (artifactName) {
// Revert everything except the one artifact
const newArtifacts = await assetSaver.loadArtifacts(artifactPath);
if (!(artifactName in newArtifacts) && !(artifactName in oldArtifacts)) {
console.warn(`❌ Unknown artifact name: '${artifactName}'. Reverting artifacts...`); // eslint-disable-line no-console
}
const finalArtifacts = oldArtifacts;
finalArtifacts[artifactName] = newArtifacts[artifactName];
Copy link
Member

Choose a reason for hiding this comment

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

do we want to log a warning if artifactName isn't a key on newArtifacts or oldArtifacts (need to check both in case it's adding a new one or removing an old one?)

At worst an unknown key will just have no effect and we don't want to throw because it'll leave things in a bad state, but it might be good to let the user know they spelled something wrong or whatever

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will throw now if it can't find the artifact name.

await assetSaver.saveArtifacts(finalArtifacts, artifactPath);
}
}

update();
update(/** @type {keyof LH.Artifacts | undefined} */ (process.argv[2]));
2 changes: 1 addition & 1 deletion lighthouse-core/test/results/artifacts/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2023,4 +2023,4 @@
"systemId": "",
"publicId": ""
}
}
}