Skip to content

Commit 39f5e14

Browse files
author
John Doe
committed
refactor: fix unit tests
1 parent fd3f13b commit 39f5e14

File tree

4 files changed

+38
-52
lines changed

4 files changed

+38
-52
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"type": "module",
4141
"bin": {
42-
"code-pushup": "./src/index.js"
42+
"code-pushup": "./src/index.mjs"
4343
},
4444
"engines": {
4545
"node": ">=20"

packages/create-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@code-pushup/create-cli",
33
"version": "0.80.2",
44
"license": "MIT",
5-
"bin": "index.js",
5+
"bin": "src/index.mjs",
66
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/create-cli#readme",
77
"bugs": {
88
"url": "https://github.com/code-pushup/cli/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20label%3A\"🧩%20create-cli\""

packages/plugin-lighthouse/src/lib/runner/constants.ts

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,44 @@ const { audits, categories } = defaultConfig;
1313

1414
export const PLUGIN_SLUG = 'lighthouse';
1515

16-
// Initialize with empty arrays - will be populated by initializeLighthouseConstants()
17-
export let LIGHTHOUSE_NAVIGATION_AUDITS: Audit[] = [];
18-
export let LIGHTHOUSE_GROUPS: Group[] = [];
16+
const allRawLighthouseAudits = await Promise.all(
17+
(audits ?? []).map(loadLighthouseAudit),
18+
);
1919

20-
// Lazy initialization flag
21-
let initialized = false;
20+
export const LIGHTHOUSE_NAVIGATION_AUDITS: Audit[] = allRawLighthouseAudits
21+
// This plugin only supports the "navigation" mode of Lighthouse in the current implementation
22+
// If we don't exclude other audits we throw in the plugin output validation as some of the provided audits are not included in `lighthouse-report.json`
23+
.filter(
24+
audit =>
25+
audit.meta.supportedModes == null ||
26+
(Array.isArray(audit.meta.supportedModes) &&
27+
audit.meta.supportedModes.includes('navigation')),
28+
)
29+
.map(audit => ({
30+
slug: audit.meta.id,
31+
title: getMetaString(audit.meta.title),
32+
description: getMetaString(audit.meta.description),
33+
}));
2234

23-
// Call this once before using the constants
24-
export async function initializeLighthouseConstants(): Promise<void> {
25-
if (initialized) {
26-
return;
27-
}
28-
29-
const allRawLighthouseAudits = await Promise.all(
30-
(audits ?? []).map(loadLighthouseAudit),
31-
);
32-
33-
LIGHTHOUSE_NAVIGATION_AUDITS = allRawLighthouseAudits
34-
// This plugin only supports the "navigation" mode of Lighthouse in the current implementation
35-
// If we don't exclude other audits we throw in the plugin output validation as some of the provided audits are not included in `lighthouse-report.json`
36-
.filter(
37-
audit =>
38-
audit.meta.supportedModes == null ||
39-
(Array.isArray(audit.meta.supportedModes) &&
40-
audit.meta.supportedModes.includes('navigation')),
41-
)
42-
.map(audit => ({
43-
slug: audit.meta.id,
44-
title: getMetaString(audit.meta.title),
45-
description: getMetaString(audit.meta.description),
46-
}));
35+
const navigationAuditSlugs = new Set(
36+
LIGHTHOUSE_NAVIGATION_AUDITS.map(({ slug }) => slug),
37+
);
4738

48-
const navigationAuditSlugs = new Set(
49-
LIGHTHOUSE_NAVIGATION_AUDITS.map(({ slug }) => slug),
50-
);
51-
52-
LIGHTHOUSE_GROUPS = Object.entries(categories ?? {}).map(
53-
([id, category]) => ({
54-
slug: id,
55-
title: getMetaString(category.title),
56-
...(category.description && {
57-
description: getMetaString(category.description),
58-
}),
59-
refs: category.auditRefs
60-
.filter(({ id: auditSlug }) => navigationAuditSlugs.has(auditSlug))
61-
.map(ref => ({
62-
slug: ref.id,
63-
weight: ref.weight,
64-
})),
39+
export const LIGHTHOUSE_GROUPS: Group[] = Object.entries(categories ?? {}).map(
40+
([id, category]) => ({
41+
slug: id,
42+
title: getMetaString(category.title),
43+
...(category.description && {
44+
description: getMetaString(category.description),
6545
}),
66-
);
67-
68-
initialized = true;
69-
}
46+
refs: category.auditRefs
47+
.filter(({ id: auditSlug }) => navigationAuditSlugs.has(auditSlug))
48+
.map(ref => ({
49+
slug: ref.id,
50+
weight: ref.weight,
51+
})),
52+
}),
53+
);
7054

7155
function getMetaString(value: string | IcuMessage): string {
7256
if (typeof value === 'string') {

packages/plugin-lighthouse/tsdown.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ const __dirname = import.meta.dirname;
55

66
export default defineConfig({
77
...baseConfig({ projectRoot: __dirname }),
8+
// Override format to ESM only - this package uses top-level await in constants.ts
9+
format: ['esm'],
810
external: await getExternalDependencies(__dirname),
911
});

0 commit comments

Comments
 (0)