lighthouse 9.5.0-dev.20220626 → 9.5.0-dev.20220629

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/report/bundle.esm.js +7 -6
  2. package/dist/report/flow.js +24 -24
  3. package/dist/report/standalone.js +19 -19
  4. package/flow-report/test/common-test.tsx +5 -4
  5. package/flow-report/test/flow-report-pptr-test.ts +4 -7
  6. package/flow-report/test/run-flow-report-tests.sh +20 -0
  7. package/flow-report/test/setup/env-setup.ts +44 -24
  8. package/flow-report/test/sidebar/sidebar-test.tsx +0 -1
  9. package/flow-report/test/topbar-test.tsx +5 -5
  10. package/flow-report/test/util-test.tsx +3 -3
  11. package/flow-report/tsconfig.json +4 -1
  12. package/lighthouse-cli/cli-flags.js +313 -305
  13. package/lighthouse-cli/test/smokehouse/report-assert-test.js +1 -1
  14. package/lighthouse-core/audits/byte-efficiency/uses-responsive-images.js +30 -5
  15. package/lighthouse-core/audits/network-requests.js +79 -62
  16. package/lighthouse-core/audits/preload-lcp-image.js +33 -7
  17. package/lighthouse-core/config/config-plugin.js +26 -0
  18. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +1 -0
  19. package/lighthouse-core/gather/gather-runner.js +1 -0
  20. package/lighthouse-core/gather/gatherers/main-document-content.js +0 -2
  21. package/lighthouse-core/lib/dependency-graph/network-node.js +1 -1
  22. package/lighthouse-core/lib/lh-env.js +1 -1
  23. package/lighthouse-core/lib/navigation-error.js +26 -7
  24. package/lighthouse-core/util-commonjs.js +7 -6
  25. package/package.json +24 -19
  26. package/report/renderer/util.js +7 -6
  27. package/report/test/.eslintrc.cjs +4 -1
  28. package/report/test/clients/bundle-test.js +4 -4
  29. package/report/test/generator/report-generator-test.js +3 -1
  30. package/report/test/renderer/category-renderer-test.js +3 -3
  31. package/report/test/renderer/components-test.js +36 -34
  32. package/report/test/renderer/crc-details-renderer-test.js +2 -2
  33. package/report/test/renderer/details-renderer-test.js +2 -2
  34. package/report/test/renderer/dom-test.js +4 -4
  35. package/report/test/renderer/element-screenshot-renderer-test.js +3 -2
  36. package/report/test/renderer/performance-category-renderer-test.js +4 -4
  37. package/report/test/renderer/pwa-category-renderer-test.js +3 -3
  38. package/report/test/renderer/report-renderer-axe-test.js +6 -8
  39. package/report/test/renderer/report-renderer-test.js +5 -5
  40. package/report/test/renderer/report-ui-features-test.js +8 -8
  41. package/report/test/renderer/snippet-renderer-test.js +2 -2
  42. package/report/test/renderer/text-encoding-test.js +2 -2
  43. package/report/test/renderer/util-test.js +1 -1
  44. package/root.js +0 -18
  45. package/shared/localization/locales/en-US.json +3 -0
  46. package/shared/localization/locales/en-XL.json +3 -0
  47. package/shared/test/localization/.eslintrc.cjs +4 -1
  48. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +1 -1
  49. package/third-party/chromium-synchronization/installability-errors-test.js +1 -3
  50. package/types/test.d.ts +53 -0
  51. package/flow-report/jest.config.js +0 -24
  52. package/flow-report/test/setup/global-setup.ts +0 -11
  53. package/jest.config.js +0 -30
  54. package/types/jest.d.ts +0 -25
@@ -4,18 +4,19 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import {jest} from '@jest/globals';
7
+ import jestMock from 'jest-mock';
8
8
  import {act, render} from '@testing-library/preact';
9
9
 
10
+ import {timers} from '../../lighthouse-core/test/test-env/fake-timers.js';
10
11
  import {FlowStepThumbnail} from '../src/common';
11
12
 
12
13
  let lhr: LH.Result;
13
14
 
14
- jest.useFakeTimers();
15
+ timers.useFakeTimers();
15
16
 
16
17
  describe('FlowStepThumbnail', () => {
17
18
  beforeEach(() => {
18
- global.console.warn = jest.fn();
19
+ global.console.warn = jestMock.fn();
19
20
 
20
21
  lhr = {
21
22
  gatherMode: 'navigation',
@@ -97,7 +98,7 @@ describe('FlowStepThumbnail', () => {
97
98
 
98
99
  expect(thumbnail.src).toContain('frame1');
99
100
  await act(() => {
100
- jest.advanceTimersByTime(501);
101
+ timers.advanceTimersByTime(501);
101
102
  });
102
103
  expect(thumbnail.src).toContain('frame2');
103
104
  });
@@ -4,14 +4,11 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import {jest} from '@jest/globals';
8
7
  import puppeteer, {Browser, Page} from 'puppeteer';
9
8
 
10
9
  import ReportGenerator from '../../report/generator/report-generator.js';
11
10
  import {flowResult} from './sample-flow';
12
11
 
13
- jest.setTimeout(35_000);
14
-
15
12
  describe('Lighthouse Flow Report', () => {
16
13
  console.log('\n✨ Be sure to have recently run this: yarn build-report');
17
14
 
@@ -19,7 +16,7 @@ describe('Lighthouse Flow Report', () => {
19
16
  let page: Page;
20
17
  const pageErrors: Error[] = [];
21
18
 
22
- beforeAll(async () => {
19
+ before(async () => {
23
20
  browser = await puppeteer.launch({
24
21
  headless: true,
25
22
  });
@@ -27,14 +24,14 @@ describe('Lighthouse Flow Report', () => {
27
24
  page.on('pageerror', pageError => pageErrors.push(pageError));
28
25
  });
29
26
 
30
- afterAll(async () => {
27
+ after(async () => {
31
28
  if (pageErrors.length > 0) console.error(pageErrors);
32
29
 
33
30
  await browser.close();
34
31
  });
35
32
 
36
33
  describe('Renders the flow report', () => {
37
- beforeAll(async () => {
34
+ before(async () => {
38
35
  const html = ReportGenerator.generateFlowReportHtml(flowResult);
39
36
  await page.setContent(html);
40
37
  });
@@ -43,4 +40,4 @@ describe('Lighthouse Flow Report', () => {
43
40
  expect(pageErrors).toHaveLength(0);
44
41
  });
45
42
  });
46
- });
43
+ }).timeout(35_000);
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##
4
+ # @license Copyright 2022 The Lighthouse Authors. All Rights Reserved.
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
7
+ ##
8
+
9
+ set -eux
10
+
11
+ ARGS=(
12
+ --testMatch='{flow-report/**/*-test.ts,flow-report/**/*-test.tsx}'
13
+ --require=flow-report/test/setup/env-setup.ts
14
+ --loader=@esbuild-kit/esm-loader
15
+ # util-test.tsx won't finish on its own because of an open MessagePort, so help it out.
16
+ # See https://github.com/jsdom/jsdom/issues/2448#issuecomment-802288244
17
+ --exit
18
+ )
19
+
20
+ yarn mocha ${ARGS[*]} "$@"
@@ -4,29 +4,49 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import {jest} from '@jest/globals';
7
+ import fs from 'fs';
8
+ import {MessageChannel} from 'worker_threads';
9
+
10
+ import jestMock from 'jest-mock';
8
11
  import {JSDOM} from 'jsdom';
12
+ import * as preact from 'preact';
9
13
 
10
- /**
11
- * The jest environment "jsdom" does not work when preact is combined with the report renderer.
12
- * This sets up our own environment with JSDOM globals.
13
- */
14
- beforeEach(() => {
15
- const {window} = new JSDOM(undefined, {
16
- url: 'file:///Users/example/report.html/',
17
- });
18
- global.window = window as any;
19
- global.document = window.document;
20
- global.location = window.location;
21
- global.self = global.window;
22
-
23
- // Use JSDOM types as necessary.
24
- global.Blob = window.Blob;
25
- global.HTMLInputElement = window.HTMLInputElement;
26
-
27
- // Functions not implemented in JSDOM.
28
- window.Element.prototype.scrollIntoView = jest.fn();
29
- global.self.matchMedia = jest.fn<any, any>(() => ({
30
- addListener: jest.fn(),
31
- }));
32
- });
14
+ import {LH_ROOT} from '../../../root.js';
15
+
16
+ // These modules aren't imported correctly if these directories aren't defined to use ES modules.
17
+ // Similar to this, which was resolved but their fix didn't work for us:
18
+ // https://github.com/testing-library/preact-testing-library/issues/36#issuecomment-1136484478
19
+ fs.writeFileSync(`${LH_ROOT}/node_modules/@testing-library/preact/dist/esm/package.json`,
20
+ '{"type": "module"}');
21
+ fs.writeFileSync(`${LH_ROOT}/node_modules/@testing-library/preact-hooks/src/package.json`,
22
+ '{"type": "module"}');
23
+
24
+ // @ts-expect-error
25
+ global.React = preact;
26
+
27
+ export default {
28
+ mochaHooks: {
29
+ beforeEach() {
30
+ const {window} = new JSDOM(undefined, {
31
+ url: 'file:///Users/example/report.html/',
32
+ });
33
+ global.window = window as any;
34
+ global.document = window.document;
35
+ global.location = window.location;
36
+ global.self = global.window;
37
+
38
+ // Use JSDOM types as necessary.
39
+ global.Blob = window.Blob;
40
+ global.HTMLInputElement = window.HTMLInputElement;
41
+
42
+ // Functions not implemented in JSDOM.
43
+ window.Element.prototype.scrollIntoView = jestMock.fn();
44
+ global.self.matchMedia = jestMock.fn<any, any>(() => ({
45
+ addListener: jestMock.fn(),
46
+ }));
47
+
48
+ // @ts-expect-error: for @testing-library/preact-hooks
49
+ global.MessageChannel = MessageChannel;
50
+ },
51
+ },
52
+ };
@@ -12,7 +12,6 @@ import {SidebarHeader, SidebarRuntimeSettings, SidebarSummary} from '../../src/s
12
12
  import {FlowResultContext} from '../../src/util';
13
13
  import {flowResult} from '../sample-flow';
14
14
 
15
-
16
15
  let wrapper: FunctionComponent;
17
16
 
18
17
  beforeEach(() => {
@@ -4,7 +4,7 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import {jest} from '@jest/globals';
7
+ import jestMock from 'jest-mock';
8
8
  import {FunctionComponent} from 'preact';
9
9
  import {act, render} from '@testing-library/preact';
10
10
 
@@ -12,7 +12,7 @@ import {FlowResultContext, OptionsContext} from '../src/util';
12
12
  import {I18nProvider} from '../src/i18n/i18n';
13
13
  import {Topbar, saveHtml} from '../src/topbar';
14
14
 
15
- const mockSaveFile = jest.fn();
15
+ const mockSaveFile = jestMock.fn();
16
16
  const defaultSaveFile = saveHtml.saveFile;
17
17
 
18
18
  const flowResult = {
@@ -27,7 +27,7 @@ const flowResult = {
27
27
  let wrapper: FunctionComponent;
28
28
  let options: LH.FlowReportOptions;
29
29
 
30
- beforeEach(() => {
30
+ before(() => {
31
31
  mockSaveFile.mockReset();
32
32
  options = {};
33
33
  wrapper = ({children}) => (
@@ -41,7 +41,7 @@ beforeEach(() => {
41
41
  );
42
42
  });
43
43
 
44
- afterEach(() => {
44
+ after(() => {
45
45
  saveHtml.saveFile = defaultSaveFile;
46
46
  });
47
47
 
@@ -60,7 +60,7 @@ it('save button opens save dialog for HTML file', async () => {
60
60
  });
61
61
 
62
62
  it('provides save as gist option if defined', async () => {
63
- const saveAsGist = jest.fn();
63
+ const saveAsGist = jestMock.fn();
64
64
  options = {saveAsGist};
65
65
  const root = render(<Topbar onMenuClick={() => {}}/>, {wrapper});
66
66
 
@@ -4,9 +4,9 @@
4
4
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
5
  */
6
6
 
7
- import {jest} from '@jest/globals';
7
+ import jestMock from 'jest-mock';
8
8
  import {render} from '@testing-library/preact';
9
- import {renderHook} from '@testing-library/preact-hooks';
9
+ import {renderHook} from '@testing-library/preact-hooks/src/index';
10
10
  import {FunctionComponent} from 'preact';
11
11
  import {act} from 'preact/test-utils';
12
12
 
@@ -16,7 +16,7 @@ import {flowResult} from './sample-flow';
16
16
  let wrapper: FunctionComponent;
17
17
 
18
18
  beforeEach(() => {
19
- global.console.warn = jest.fn();
19
+ global.console.warn = jestMock.fn();
20
20
  wrapper = ({children}) => (
21
21
  <FlowResultContext.Provider value={flowResult}>{children}</FlowResultContext.Provider>
22
22
  );
@@ -4,7 +4,7 @@
4
4
  // Limit to base JS and DOM defs.
5
5
  "lib": ["es2020", "dom", "dom.iterable"],
6
6
  // Selectively include types from node_modules/.
7
- "types": ["node", "jest"],
7
+ "types": ["node", "mocha"],
8
8
 
9
9
  "jsx": "react-jsx",
10
10
  "jsxImportSource": "preact",
@@ -19,5 +19,8 @@
19
19
  "**/*.ts",
20
20
  "**/*.tsx",
21
21
  "./types",
22
+ "../types/test.d.ts",
23
+ "../root.js",
24
+ "../lighthouse-core/test/test-env/fake-timers.js",
22
25
  ],
23
26
  }