lighthouse 11.0.0-dev.20230809 → 11.0.0-dev.20230810
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.
- package/core/lib/asset-saver.d.ts +0 -3
- package/core/lib/asset-saver.js +67 -41
- package/core/runner.js +3 -2
- package/dependabot.yml +10 -0
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type PreparedAssets = {
|
|
2
|
-
passName: string;
|
|
3
2
|
traceData: LH.Trace;
|
|
4
3
|
devtoolsLog: import("../index.js").DevtoolsLog;
|
|
5
4
|
};
|
|
@@ -35,7 +34,6 @@ export function saveFlowArtifacts(flowArtifacts: LH.UserFlow.FlowArtifacts, base
|
|
|
35
34
|
export function saveLhr(lhr: LH.Result, basePath: string): void;
|
|
36
35
|
/**
|
|
37
36
|
* @typedef {object} PreparedAssets
|
|
38
|
-
* @property {string} passName
|
|
39
37
|
* @property {LH.Trace} traceData
|
|
40
38
|
* @property {LH.DevtoolsLog} devtoolsLog
|
|
41
39
|
*/
|
|
@@ -60,7 +58,6 @@ export function loadFlowArtifacts(basePath: string): LH.UserFlow.FlowArtifacts;
|
|
|
60
58
|
*/
|
|
61
59
|
export function saveAssets(artifacts: LH.Artifacts, audits: LH.Result['audits'], pathWithBasename: string): Promise<void>;
|
|
62
60
|
/**
|
|
63
|
-
* Filter traces and extract screenshots to prepare for saving.
|
|
64
61
|
* @param {LH.Artifacts} artifacts
|
|
65
62
|
* @param {LH.Result['audits']} [audits]
|
|
66
63
|
* @return {Promise<Array<PreparedAssets>>}
|
package/core/lib/asset-saver.js
CHANGED
|
@@ -23,11 +23,12 @@ const optionsFilename = 'options.json';
|
|
|
23
23
|
const artifactsFilename = 'artifacts.json';
|
|
24
24
|
const traceSuffix = '.trace.json';
|
|
25
25
|
const devtoolsLogSuffix = '.devtoolslog.json';
|
|
26
|
+
const defaultPrefix = 'defaultPass';
|
|
27
|
+
const errorPrefix = 'pageLoadError-defaultPass';
|
|
26
28
|
const stepDirectoryRegex = /^step(\d+)$/;
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* @typedef {object} PreparedAssets
|
|
30
|
-
* @property {string} passName
|
|
31
32
|
* @property {LH.Trace} traceData
|
|
32
33
|
* @property {LH.DevtoolsLog} devtoolsLog
|
|
33
34
|
*/
|
|
@@ -53,32 +54,30 @@ function loadArtifacts(basePath) {
|
|
|
53
54
|
|
|
54
55
|
const filenames = fs.readdirSync(basePath);
|
|
55
56
|
|
|
56
|
-
// load devtoolsLogs
|
|
57
|
-
artifacts.devtoolsLogs = {};
|
|
58
57
|
filenames.filter(f => f.endsWith(devtoolsLogSuffix)).forEach(filename => {
|
|
59
|
-
|
|
58
|
+
if (!artifacts.devtoolsLogs) artifacts.devtoolsLogs = {};
|
|
59
|
+
const prefix = filename.replace(devtoolsLogSuffix, '');
|
|
60
60
|
const devtoolsLog = JSON.parse(fs.readFileSync(path.join(basePath, filename), 'utf8'));
|
|
61
|
-
artifacts.devtoolsLogs[
|
|
62
|
-
if (
|
|
61
|
+
artifacts.devtoolsLogs[prefix] = devtoolsLog;
|
|
62
|
+
if (prefix === defaultPrefix) {
|
|
63
63
|
artifacts.DevtoolsLog = devtoolsLog;
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
65
|
+
if (prefix === errorPrefix) {
|
|
66
66
|
artifacts.DevtoolsLogError = devtoolsLog;
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
// load traces
|
|
71
|
-
artifacts.traces = {};
|
|
72
70
|
filenames.filter(f => f.endsWith(traceSuffix)).forEach(filename => {
|
|
71
|
+
if (!artifacts.traces) artifacts.traces = {};
|
|
73
72
|
const file = fs.readFileSync(path.join(basePath, filename), {encoding: 'utf-8'});
|
|
74
73
|
const trace = JSON.parse(file);
|
|
75
|
-
const
|
|
76
|
-
artifacts.traces[
|
|
77
|
-
if (
|
|
78
|
-
artifacts.Trace = artifacts.traces[
|
|
74
|
+
const prefix = filename.replace(traceSuffix, '');
|
|
75
|
+
artifacts.traces[prefix] = Array.isArray(trace) ? {traceEvents: trace} : trace;
|
|
76
|
+
if (prefix === defaultPrefix) {
|
|
77
|
+
artifacts.Trace = artifacts.traces[prefix];
|
|
79
78
|
}
|
|
80
|
-
if (
|
|
81
|
-
artifacts.TraceError = artifacts.traces[
|
|
79
|
+
if (prefix === errorPrefix) {
|
|
80
|
+
artifacts.TraceError = artifacts.traces[prefix];
|
|
82
81
|
}
|
|
83
82
|
});
|
|
84
83
|
|
|
@@ -220,23 +219,34 @@ async function saveArtifacts(artifacts, basePath) {
|
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
|
|
223
|
-
// `
|
|
222
|
+
// `devtoolsLogs` and `traces` are duplicate compat artifacts.
|
|
224
223
|
// We don't need to save them twice, so extract them here.
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
const {
|
|
225
|
+
// eslint-disable-next-line no-unused-vars
|
|
226
|
+
traces,
|
|
227
|
+
// eslint-disable-next-line no-unused-vars
|
|
228
|
+
devtoolsLogs,
|
|
229
|
+
DevtoolsLog,
|
|
230
|
+
Trace,
|
|
231
|
+
DevtoolsLogError,
|
|
232
|
+
TraceError,
|
|
233
|
+
...restArtifacts
|
|
234
|
+
} = artifacts;
|
|
235
|
+
|
|
236
|
+
if (Trace) {
|
|
237
|
+
await saveTrace(Trace, `${basePath}/${defaultPrefix}${traceSuffix}`);
|
|
238
|
+
}
|
|
227
239
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
for (const [passName, trace] of Object.entries(traces)) {
|
|
231
|
-
await saveTrace(trace, `${basePath}/${passName}${traceSuffix}`);
|
|
232
|
-
}
|
|
240
|
+
if (TraceError) {
|
|
241
|
+
await saveTrace(TraceError, `${basePath}/${errorPrefix}${traceSuffix}`);
|
|
233
242
|
}
|
|
234
243
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
if (DevtoolsLog) {
|
|
245
|
+
await saveDevtoolsLog(DevtoolsLog, `${basePath}/${defaultPrefix}${devtoolsLogSuffix}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (DevtoolsLogError) {
|
|
249
|
+
await saveDevtoolsLog(DevtoolsLogError, `${basePath}/${errorPrefix}${devtoolsLogSuffix}`);
|
|
240
250
|
}
|
|
241
251
|
|
|
242
252
|
// save everything else, using a replacer to serialize LighthouseErrors in the artifacts.
|
|
@@ -256,33 +266,49 @@ function saveLhr(lhr, basePath) {
|
|
|
256
266
|
}
|
|
257
267
|
|
|
258
268
|
/**
|
|
259
|
-
* Filter
|
|
269
|
+
* Filter trace and extract screenshots to prepare for saving.
|
|
270
|
+
* @param {LH.Trace} trace
|
|
271
|
+
* @param {LH.Result['audits']} [audits]
|
|
272
|
+
* @return {LH.Trace}
|
|
273
|
+
*/
|
|
274
|
+
function prepareTraceAsset(trace, audits) {
|
|
275
|
+
if (!trace) return trace;
|
|
276
|
+
|
|
277
|
+
const traceData = Object.assign({}, trace);
|
|
278
|
+
if (audits) {
|
|
279
|
+
const evts = new MetricTraceEvents(traceData.traceEvents, audits).generateFakeEvents();
|
|
280
|
+
traceData.traceEvents = traceData.traceEvents.concat(evts);
|
|
281
|
+
}
|
|
282
|
+
return traceData;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
260
286
|
* @param {LH.Artifacts} artifacts
|
|
261
287
|
* @param {LH.Result['audits']} [audits]
|
|
262
288
|
* @return {Promise<Array<PreparedAssets>>}
|
|
263
289
|
*/
|
|
264
290
|
async function prepareAssets(artifacts, audits) {
|
|
265
|
-
const passNames = Object.keys(artifacts.traces);
|
|
266
291
|
/** @type {Array<PreparedAssets>} */
|
|
267
292
|
const assets = [];
|
|
268
293
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const traceData = Object.assign({}, trace);
|
|
274
|
-
if (audits) {
|
|
275
|
-
const evts = new MetricTraceEvents(traceData.traceEvents, audits).generateFakeEvents();
|
|
276
|
-
traceData.traceEvents = traceData.traceEvents.concat(evts);
|
|
277
|
-
}
|
|
278
|
-
|
|
294
|
+
const devtoolsLog = artifacts.DevtoolsLog;
|
|
295
|
+
const traceData = prepareTraceAsset(artifacts.Trace, audits);
|
|
296
|
+
if (traceData || devtoolsLog) {
|
|
279
297
|
assets.push({
|
|
280
|
-
passName,
|
|
281
298
|
traceData,
|
|
282
299
|
devtoolsLog,
|
|
283
300
|
});
|
|
284
301
|
}
|
|
285
302
|
|
|
303
|
+
const devtoolsLogError = artifacts.DevtoolsLogError;
|
|
304
|
+
const traceErrorData = prepareTraceAsset(artifacts.TraceError, audits);
|
|
305
|
+
if (devtoolsLogError || traceErrorData) {
|
|
306
|
+
assets.push({
|
|
307
|
+
traceData: traceErrorData,
|
|
308
|
+
devtoolsLog: devtoolsLogError,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
286
312
|
return assets;
|
|
287
313
|
}
|
|
288
314
|
|
package/core/runner.js
CHANGED
|
@@ -375,9 +375,10 @@ class Runner {
|
|
|
375
375
|
|
|
376
376
|
// If trace/devtoolsLog required, check that DEFAULT_PASS trace/devtoolsLog exists.
|
|
377
377
|
// NOTE: for now, not a pass-specific check of traces or devtoolsLogs.
|
|
378
|
-
const noRequiredTrace = artifactName === 'traces' &&
|
|
378
|
+
const noRequiredTrace = artifactName === 'traces' &&
|
|
379
|
+
!artifacts.traces?.[Audit.DEFAULT_PASS];
|
|
379
380
|
const noRequiredDevtoolsLog = artifactName === 'devtoolsLogs' &&
|
|
380
|
-
|
|
381
|
+
!artifacts.devtoolsLogs?.[Audit.DEFAULT_PASS];
|
|
381
382
|
|
|
382
383
|
if (noArtifact || noRequiredTrace || noRequiredDevtoolsLog) {
|
|
383
384
|
log.warn('Runner',
|
package/dependabot.yml
ADDED
package/package.json
CHANGED