Skip to content

Commit badea06

Browse files
authored
audit diff: use good keys for nodes and taptargets (#883)
1 parent 7c8d0a9 commit badea06

File tree

32 files changed

+34
-4
lines changed

32 files changed

+34
-4
lines changed

CONTRIBUTING.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,21 @@ yarn install # run in the repo root
4646

4747
When working on the CLI, simply make your changes to `packages/cli` or `packages/utils` files and run `yarn start <LHCI arguments here>`. No build step necessary.
4848

49-
When working on the server, you'll need to start build in watch mode. In one terminal run `yarn build:watch` from the repo root. In another terminal run `yarn start:server`. If you made any changes to the APIs of the server, you will need to restart the `yarn start:server` command, but UI changes should be picked up on refresh without restarting the server process. Once the server is up and running you can fill it with some test data by running `yarn start:seed-database` in another terminal.
49+
When working on the server, you'll need to build. `yarn build` in root will build the server and viewer. Also, you can use watch mode.
50+
51+
```sh
52+
yarn build:watch
53+
yarn start:server
54+
```
55+
56+
If you made any changes to the APIs of the server, you will need to restart the `yarn start:server` command, but UI changes should be picked up on refresh without restarting the server process. Once the server is up and running you can fill it with some test data with `yarn start:seed-database`.
57+
58+
## Problems?
59+
60+
```sh
61+
trash node_modules && yarn install
62+
yarn build
63+
```
5064

5165
## Updating the Lighthouse Version
5266

packages/server/test/test-utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ module.exports = {
279279
// FIXME: we're more forgiving in CI where font rendering creates small changes.,
280280
// failureThreshold: process.env.CI ? 0.005 : 0.001,
281281
failureThresholdType: 'percent',
282+
// On -u dont update files that are already fine. This should match the default but...
283+
// we've seen behavior which seemingly conflicts.
284+
updatePassedSnapshot: false,
282285
});
283286

284287
expect.extend({toMatchImageSnapshot});

packages/server/test/ui/storybook.test.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ if (process.env.CI && require('os').platform() !== 'darwin') {
2525
initStoryshots({
2626
configPath: path.join(__dirname, '../../.storybook'),
2727
suite: 'Image Storyshots',
28+
// Use a storyKindRegex as an `.only`-like filter on the "Image Storyshots" tests.
29+
// storyKindRegex: /Graph/,
2830
test: imageSnapshot({
2931
storybookUrl: `http://localhost:${process.env.STORYBOOK_PORT}`,
3032
beforeScreenshot: async page => {

packages/utils/src/audit-diff-finder.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,8 @@ function deepPruneItemForKeySerialization(item) {
384384

385385
/** @param {Record<string, any>} item @return {string} */
386386
function getItemKey(item) {
387-
// For most opportunities, diagnostics, etc where 1 row === 1 resource
388-
if (typeof item.url === 'string' && item.url) return item.url;
389-
if (typeof item.origin === 'string' && item.origin) return item.origin;
387+
// Do most specific checks at the top. most general at bottom..
388+
//
390389
// For sourcemapped opportunities that identify a source location
391390
const source = item.source;
392391
if (typeof source === 'string') return source;
@@ -401,6 +400,18 @@ function getItemKey(item) {
401400
if (typeof item.statistic === 'string') return item.statistic;
402401
// For third-party-summary
403402
if (item.entity && typeof item.entity.text === 'string') return item.entity.text;
403+
// For node
404+
if (typeof item.node?.path === 'string') return item.node.path;
405+
// Tap-targets
406+
if (
407+
typeof item.tapTarget?.path === 'string' &&
408+
typeof item.overlappingTarget?.path === 'string'
409+
) {
410+
return `${item.tapTarget.path} + ${item.overlappingTarget.path}`;
411+
}
412+
// For most opportunities, diagnostics, etc where 1 row === 1 resource
413+
if (typeof item.url === 'string' && item.url) return item.url;
414+
if (typeof item.origin === 'string' && item.origin) return item.origin;
404415

405416
// For everything else, use the entire object, actually works OK on most nodes.
406417
return JSON.stringify(deepPruneItemForKeySerialization(item));

0 commit comments

Comments
 (0)