lighthouse-reporting 1.4.0 → 1.6.0
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/README.md +4 -1
- package/dist/lighthouse-reporting.umd.cjs +7 -3
- package/dist/lighthouseReports.cjs +5 -2
- package/dist/lighthouseReports.d.ts +4 -2
- package/dist/lighthouseReports.js +5 -2
- package/dist/storybookPlaywright.cjs +2 -1
- package/dist/storybookPlaywright.d.ts +20 -3
- package/dist/storybookPlaywright.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,6 +100,8 @@ const lhScoresDir = path.join(process.cwd(), process.env.LH_SCORES_DIR || 'lh-sc
|
|
|
100
100
|
const reportDir = path.join(process.cwd(), process.env.LH_REPORT_DIR || 'lighthouse')
|
|
101
101
|
const htmlFilePath = path.join(reportDir, 'index.html')
|
|
102
102
|
|
|
103
|
+
// use stories.json instead of index.json for storybook v6
|
|
104
|
+
// make sure to set buildStoriesJson to true in storybook main.js feature section
|
|
103
105
|
const stories = storybookPlaywright.getStories('./storybook-static/index.json', (story) => {
|
|
104
106
|
// skip docs, etc
|
|
105
107
|
if (story.type !== 'story') {
|
|
@@ -233,10 +235,11 @@ export default globalSetup
|
|
|
233
235
|
import { lighthousePlaywrightTeardown, buildAverageCsv } from 'lighthouse-reporting'
|
|
234
236
|
|
|
235
237
|
const lhScoresDir = path.join(process.cwd(), process.env.LH_SCORES_DIR || 'lh-scores')
|
|
238
|
+
const reportDir = path.join(process.cwd(), 'lighthouse')
|
|
236
239
|
|
|
237
240
|
async function globalTeardown() {
|
|
238
241
|
await lighthousePlaywrightTeardown()
|
|
239
|
-
await buildAverageCsv(lhScoresDir)
|
|
242
|
+
await buildAverageCsv(lhScoresDir, reportDir)
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
export default globalTeardown
|
|
@@ -77,9 +77,12 @@
|
|
|
77
77
|
}
|
|
78
78
|
await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
|
|
79
79
|
};
|
|
80
|
-
const buildAverageCsv = async (lhScoresDir) => {
|
|
80
|
+
const buildAverageCsv = async (lhScoresDir, reportDir2) => {
|
|
81
81
|
const files = await fse.readdir(lhScoresDir);
|
|
82
82
|
const jsonFiles = files.filter((f) => f.endsWith(".json"));
|
|
83
|
+
if (jsonFiles.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
83
86
|
const scores = {};
|
|
84
87
|
for (const fileName of jsonFiles) {
|
|
85
88
|
const score = await fse.readJson(
|
|
@@ -95,7 +98,7 @@
|
|
|
95
98
|
Object.entries(scores).forEach(([k, v]) => {
|
|
96
99
|
scores[k] = v / jsonFiles.length;
|
|
97
100
|
});
|
|
98
|
-
await writeCsvResult(
|
|
101
|
+
await writeCsvResult(reportDir2, "_AVERAGE_", scores);
|
|
99
102
|
};
|
|
100
103
|
class Locked extends Error {
|
|
101
104
|
constructor(port) {
|
|
@@ -236,7 +239,8 @@
|
|
|
236
239
|
throw new Error("Please build storybook before running tests!");
|
|
237
240
|
}
|
|
238
241
|
const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
|
|
239
|
-
const
|
|
242
|
+
const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
|
|
243
|
+
const stories = Object.values(storyObject).filter(storyFilterFn);
|
|
240
244
|
return stories;
|
|
241
245
|
},
|
|
242
246
|
captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
|
|
@@ -58,9 +58,12 @@ const writeScoresToJson = async (lhScoresDir, name, scores, result) => {
|
|
|
58
58
|
}
|
|
59
59
|
await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
|
|
60
60
|
};
|
|
61
|
-
const buildAverageCsv = async (lhScoresDir) => {
|
|
61
|
+
const buildAverageCsv = async (lhScoresDir, reportDir) => {
|
|
62
62
|
const files = await fse.readdir(lhScoresDir);
|
|
63
63
|
const jsonFiles = files.filter((f) => f.endsWith(".json"));
|
|
64
|
+
if (jsonFiles.length === 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
64
67
|
const scores = {};
|
|
65
68
|
for (const fileName of jsonFiles) {
|
|
66
69
|
const score = await fse.readJson(
|
|
@@ -76,7 +79,7 @@ const buildAverageCsv = async (lhScoresDir) => {
|
|
|
76
79
|
Object.entries(scores).forEach(([k, v]) => {
|
|
77
80
|
scores[k] = v / jsonFiles.length;
|
|
78
81
|
});
|
|
79
|
-
await writeCsvResult(
|
|
82
|
+
await writeCsvResult(reportDir, "_AVERAGE_", scores);
|
|
80
83
|
};
|
|
81
84
|
exports.buildAverageCsv = buildAverageCsv;
|
|
82
85
|
exports.getScores = getScores;
|
|
@@ -52,7 +52,9 @@ export declare const writeHtmlListEntryWithRetry: (htmlFilePath: string, name: s
|
|
|
52
52
|
export declare const getScores: (result: LighthouseResult) => Record<string, number>;
|
|
53
53
|
export declare const writeScoresToJson: (lhScoresDir: string, name: string, scores: Record<string, number>, result: LighthouseResult) => Promise<void>;
|
|
54
54
|
/**
|
|
55
|
-
* Generate average csv file. Make sure to use writeScoresToJson in your test!
|
|
55
|
+
* Generate average csv file. Make sure to use `writeScoresToJson` in your test!
|
|
56
|
+
* @param lhScoresDir path to folder with lighthouse json files. See `writeScoresToJson`.
|
|
57
|
+
* @param reportDir folder where `_AVERAGE_.json` will be generated
|
|
56
58
|
*/
|
|
57
|
-
export declare const buildAverageCsv: (lhScoresDir: string) => Promise<void>;
|
|
59
|
+
export declare const buildAverageCsv: (lhScoresDir: string, reportDir: string) => Promise<void>;
|
|
58
60
|
export {};
|
|
@@ -56,9 +56,12 @@ const writeScoresToJson = async (lhScoresDir, name, scores, result) => {
|
|
|
56
56
|
}
|
|
57
57
|
await fse.writeFile(path.join(lhScoresDir, `${name}.json`), JSON.stringify(json, null, 2));
|
|
58
58
|
};
|
|
59
|
-
const buildAverageCsv = async (lhScoresDir) => {
|
|
59
|
+
const buildAverageCsv = async (lhScoresDir, reportDir) => {
|
|
60
60
|
const files = await fse.readdir(lhScoresDir);
|
|
61
61
|
const jsonFiles = files.filter((f) => f.endsWith(".json"));
|
|
62
|
+
if (jsonFiles.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
62
65
|
const scores = {};
|
|
63
66
|
for (const fileName of jsonFiles) {
|
|
64
67
|
const score = await fse.readJson(
|
|
@@ -74,7 +77,7 @@ const buildAverageCsv = async (lhScoresDir) => {
|
|
|
74
77
|
Object.entries(scores).forEach(([k, v]) => {
|
|
75
78
|
scores[k] = v / jsonFiles.length;
|
|
76
79
|
});
|
|
77
|
-
await writeCsvResult(
|
|
80
|
+
await writeCsvResult(reportDir, "_AVERAGE_", scores);
|
|
78
81
|
};
|
|
79
82
|
export {
|
|
80
83
|
buildAverageCsv,
|
|
@@ -9,7 +9,8 @@ const storybookPlaywright = {
|
|
|
9
9
|
throw new Error("Please build storybook before running tests!");
|
|
10
10
|
}
|
|
11
11
|
const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
|
|
12
|
-
const
|
|
12
|
+
const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
|
|
13
|
+
const stories = Object.values(storyObject).filter(storyFilterFn);
|
|
13
14
|
return stories;
|
|
14
15
|
},
|
|
15
16
|
captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { BrowserContext, Locator, Page } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Storybook v7
|
|
4
|
+
*/
|
|
2
5
|
export interface StorybookIndexStory {
|
|
3
6
|
id: string;
|
|
4
7
|
title: string;
|
|
@@ -7,9 +10,24 @@ export interface StorybookIndexStory {
|
|
|
7
10
|
tags: Array<string>;
|
|
8
11
|
type: 'story' | 'docs';
|
|
9
12
|
}
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Storybook v6
|
|
15
|
+
*/
|
|
16
|
+
export interface StorybookStoriesStory {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
name: string;
|
|
20
|
+
importPath: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
story: string;
|
|
23
|
+
parameters: {
|
|
24
|
+
__id: string;
|
|
25
|
+
docsOnly: boolean;
|
|
26
|
+
fileName: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
11
29
|
export declare const storybookPlaywright: {
|
|
12
|
-
getStories: (pathToStorybookIndexJson: string, storyFilterFn:
|
|
30
|
+
getStories: <V7 = true>(pathToStorybookIndexJson: string, storyFilterFn: (story: V7 extends true ? StorybookIndexStory : StorybookStoriesStory) => boolean) => StorybookIndexStory[];
|
|
13
31
|
captureScreenshot: (story: StorybookIndexStory, context: BrowserContext, screenshotOptions?: {
|
|
14
32
|
/**
|
|
15
33
|
* When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different
|
|
@@ -91,4 +109,3 @@ export declare const storybookPlaywright: {
|
|
|
91
109
|
timeout?: number;
|
|
92
110
|
}, actionBeforeScreenshot?: ((page: Page) => Promise<void>) | undefined) => Promise<void>;
|
|
93
111
|
};
|
|
94
|
-
export {};
|
|
@@ -7,7 +7,8 @@ const storybookPlaywright = {
|
|
|
7
7
|
throw new Error("Please build storybook before running tests!");
|
|
8
8
|
}
|
|
9
9
|
const storybookIndexJson = fse.readJsonSync(pathToStorybookIndexJson);
|
|
10
|
-
const
|
|
10
|
+
const storyObject = storybookIndexJson.entries || storybookIndexJson.stories;
|
|
11
|
+
const stories = Object.values(storyObject).filter(storyFilterFn);
|
|
11
12
|
return stories;
|
|
12
13
|
},
|
|
13
14
|
captureScreenshot: async (story, context, screenshotOptions, actionBeforeScreenshot) => {
|