lighthouse 9.2.0-dev.20220102 → 9.2.0-dev.20220106

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.
@@ -36,6 +36,7 @@ const coreTestDefnsPath =
36
36
  const runnerPaths = {
37
37
  cli: '../lighthouse-runners/cli.js',
38
38
  bundle: '../lighthouse-runners/bundle.js',
39
+ devtools: '../lighthouse-runners/devtools.js',
39
40
  };
40
41
 
41
42
  /**
@@ -151,7 +152,7 @@ async function begin() {
151
152
  },
152
153
  'runner': {
153
154
  default: 'cli',
154
- choices: ['cli', 'bundle'],
155
+ choices: ['cli', 'bundle', 'devtools'],
155
156
  describe: 'The method of running Lighthouse',
156
157
  },
157
158
  'tests-path': {
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @license Copyright 2021 The Lighthouse Authors. All Rights Reserved.
3
+ * 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
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
+ */
6
+ 'use strict';
7
+
8
+ /**
9
+ * @fileoverview A runner that launches Chrome and executes Lighthouse via DevTools.
10
+ */
11
+
12
+ import fs from 'fs';
13
+ import os from 'os';
14
+ import {spawn} from 'child_process';
15
+
16
+ import {LH_ROOT} from '../../../../root.js';
17
+
18
+ const devtoolsDir =
19
+ process.env.DEVTOOLS_PATH || `${LH_ROOT}/.tmp/chromium-web-tests/devtools/devtools-frontend`;
20
+
21
+ /**
22
+ * @param {string} command
23
+ * @param {string[]} args
24
+ */
25
+ async function spawnAndLog(command, args) {
26
+ let log = '';
27
+
28
+ /** @type {Promise<void>} */
29
+ const promise = new Promise((resolve, reject) => {
30
+ const spawnHandle = spawn(command, args);
31
+ spawnHandle.on('close', code => {
32
+ if (code === 0) resolve();
33
+ else reject(new Error(`Command exited with code ${code}`));
34
+ });
35
+ spawnHandle.on('error', reject);
36
+ spawnHandle.stdout.on('data', data => {
37
+ console.log(data.toString());
38
+ log += `STDOUT: ${data.toString()}`;
39
+ });
40
+ spawnHandle.stderr.on('data', data => {
41
+ console.log(data.toString());
42
+ log += `STDERR: ${data.toString()}`;
43
+ });
44
+ });
45
+ await promise;
46
+
47
+ return log;
48
+ }
49
+
50
+ /** @type {Promise<void>} */
51
+ let buildDevtoolsPromise;
52
+ /**
53
+ * Download/pull latest DevTools, build Lighthouse for DevTools, roll to DevTools, and build DevTools.
54
+ */
55
+ async function buildDevtools() {
56
+ if (process.env.CI) return;
57
+
58
+ process.env.DEVTOOLS_PATH = devtoolsDir;
59
+ await spawnAndLog('bash', ['lighthouse-core/test/chromium-web-tests/download-devtools.sh']);
60
+ await spawnAndLog('bash', ['lighthouse-core/test/chromium-web-tests/roll-devtools.sh']);
61
+ }
62
+
63
+ /**
64
+ * Launch Chrome and do a full Lighthouse run via DevTools.
65
+ * By default, the latest DevTools frontend is used (.tmp/chromium-web-tests/devtools/devtools-frontend)
66
+ * unless DEVTOOLS_PATH is set.
67
+ * CHROME_PATH determines which Chrome is used–otherwise the default is puppeteer's chrome binary.
68
+ * @param {string} url
69
+ * @param {LH.Config.Json=} configJson
70
+ * @param {{isDebug?: boolean}=} testRunnerOptions
71
+ * @return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts, log: string}>}
72
+ */
73
+ async function runLighthouse(url, configJson, testRunnerOptions = {}) {
74
+ if (!buildDevtoolsPromise) buildDevtoolsPromise = buildDevtools();
75
+ await buildDevtoolsPromise;
76
+
77
+ const outputDir = fs.mkdtempSync(os.tmpdir() + '/lh-smoke-cdt-runner-');
78
+ const args = [
79
+ 'run-devtools',
80
+ url,
81
+ `--custom-devtools-frontend=file://${devtoolsDir}/out/Default/gen/front_end`,
82
+ '--output-dir', outputDir,
83
+ ];
84
+ if (configJson) {
85
+ args.push('--config', JSON.stringify(configJson));
86
+ }
87
+
88
+ const log = await spawnAndLog('yarn', args);
89
+ const lhr = JSON.parse(fs.readFileSync(`${outputDir}/lhr-0.json`, 'utf-8'));
90
+ const artifacts = JSON.parse(fs.readFileSync(`${outputDir}/artifacts-0.json`, 'utf-8'));
91
+
92
+ if (testRunnerOptions.isDebug) {
93
+ console.log(`${url} results saved at ${outputDir}`);
94
+ } else {
95
+ fs.rmSync(outputDir, {recursive: true, force: true});
96
+ }
97
+
98
+ return {lhr, artifacts, log};
99
+ }
100
+
101
+ export {
102
+ runLighthouse,
103
+ };
@@ -118,14 +118,15 @@ Smokehouse Frontends Lighthouse Runners
118
118
  | | | | | <lhr | +--------------+
119
119
  +------------+ | +-------+-------+ | | |
120
120
  | ^ +-->+ bundle.js |
121
- +------------+ | | | |
122
- | | | | +--------------+
123
- | lib.js +----+ v
124
- | | +--------+--------+
125
- +------------+ | |
126
- | report/assert |
127
- | |
128
- +-----------------+
121
+ +------------+ | | | | |
122
+ | | | | | +--------------+
123
+ | lib.js +----+ v |
124
+ | | +--------+--------+ |
125
+ +------------+ | | | +--------------+
126
+ | report/assert | | | |
127
+ | | +-->+ devtools.js |
128
+ +-----------------+ | |
129
+ +--------------+
129
130
  ```
130
131
 
131
132
  ### Smokehouse frontends
@@ -142,6 +143,7 @@ Smokehouse Frontends Lighthouse Runners
142
143
 
143
144
  - `lighthouse-runners/cli.js` - the original test runner, exercising the Lighthouse CLI from command-line argument parsing to the results written to disk on completion.
144
145
  - `lighthouse-runners/bundle.js` - a smoke test runner that operates on an already-bundled version of Lighthouse for end-to-end testing of that version.
146
+ - `lighthouse-runners/devtools.js` - a smoke test runner that operates on Lighthouse running from inside DevTools.
145
147
 
146
148
  ## Custom smoke tests (for plugins et al.)
147
149
 
@@ -10,10 +10,23 @@
10
10
 
11
11
  set -euo pipefail
12
12
 
13
- if [ "$OSTYPE" == "msys" ]; then
13
+ unameOut="$(uname -s)"
14
+ case "${unameOut}" in
15
+ Linux*) machine=Linux;;
16
+ Darwin*) machine=Mac;;
17
+ MINGW*) machine=MinGw;;
18
+ *) machine="UNKNOWN:${unameOut}"
19
+ esac
20
+
21
+ if [ "$machine" == "MinGw" ]; then
14
22
  url="https://download-chromium.appspot.com/dl/Win?type=snapshots"
15
- else
23
+ elif [ "$machine" == "Linux" ]; then
16
24
  url="https://download-chromium.appspot.com/dl/Linux_x64?type=snapshots"
25
+ elif [ "$machine" == "Mac" ]; then
26
+ url="https://download-chromium.appspot.com/dl/Mac?type=snapshots"
27
+ else
28
+ echo "unsupported platform"
29
+ exit 1
17
30
  fi
18
31
 
19
32
  if [ -e "$CHROME_PATH" ]; then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.2.0-dev.20220102",
3
+ "version": "9.2.0-dev.20220106",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -95,9 +95,6 @@
95
95
  },
96
96
  "devDependencies": {
97
97
  "@build-tracker/cli": "^1.0.0-beta.15",
98
- "@firebase/app-types": "0.3.1",
99
- "@firebase/auth-types": "0.3.2",
100
- "@firebase/util": "0.2.1",
101
98
  "@rollup/plugin-alias": "^3.1.2",
102
99
  "@rollup/plugin-commonjs": "^20.0.0",
103
100
  "@rollup/plugin-dynamic-import-vars": "^1.1.1",
@@ -115,7 +112,7 @@
115
112
  "@types/estree": "^0.0.50",
116
113
  "@types/gh-pages": "^2.0.0",
117
114
  "@types/google.analytics": "0.0.39",
118
- "@types/jest": "^24.0.9",
115
+ "@types/jest": "^27.0.3",
119
116
  "@types/jpeg-js": "^0.3.7",
120
117
  "@types/jsdom": "^16.2.13",
121
118
  "@types/lodash.clonedeep": "^4.5.6",
@@ -173,7 +170,7 @@
173
170
  "resolve": "^1.20.0",
174
171
  "rollup": "^2.52.7",
175
172
  "rollup-plugin-node-resolve": "^5.2.0",
176
- "rollup-plugin-polyfill-node": "^0.7.0",
173
+ "rollup-plugin-polyfill-node": "^0.8.0",
177
174
  "rollup-plugin-replace": "^2.2.0",
178
175
  "rollup-plugin-shim": "^1.0.0",
179
176
  "rollup-plugin-terser": "^7.0.2",