Skip to content

Commit 82b694f

Browse files
committed
Validate Astro package targets
Make the Astro package test assert each package.json entrypoint explicitly instead of relying on a cast to string[]. This prevents missing metadata fields from slipping through as false positives while keeping the regression coverage focused on the published package contract.
1 parent e43ca81 commit 82b694f

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

packages/astro/src/package.test.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ function expectResponse(response: void | Response): Response {
3232
return response;
3333
}
3434

35+
function expectTarget(actual: unknown, expected: string, key: string): string {
36+
strictEqual(actual, expected, `Expected ${key} to be ${expected}`);
37+
return actual;
38+
}
39+
3540
async function assertTargetExists(path: string): Promise<void> {
3641
await access(resolve(packageDir, path));
3742
}
@@ -105,14 +110,30 @@ test(
105110
);
106111
const exportMap = packageJson.exports["."];
107112
const targets = [
108-
packageJson.main,
109-
packageJson.module,
110-
packageJson.types,
111-
exportMap.require.types,
112-
exportMap.require.default,
113-
exportMap.import.types,
114-
exportMap.import.default,
115-
] as string[];
113+
expectTarget(packageJson.main, "./dist/mod.cjs", "package.json main"),
114+
expectTarget(packageJson.module, "./dist/mod.js", "package.json module"),
115+
expectTarget(packageJson.types, "./dist/mod.d.ts", "package.json types"),
116+
expectTarget(
117+
exportMap.require.types,
118+
"./dist/mod.d.cts",
119+
'package.json exports["."].require.types',
120+
),
121+
expectTarget(
122+
exportMap.require.default,
123+
"./dist/mod.cjs",
124+
'package.json exports["."].require.default',
125+
),
126+
expectTarget(
127+
exportMap.import.types,
128+
"./dist/mod.d.ts",
129+
'package.json exports["."].import.types',
130+
),
131+
expectTarget(
132+
exportMap.import.default,
133+
"./dist/mod.js",
134+
'package.json exports["."].import.default',
135+
),
136+
];
116137

117138
for (const target of new Set(targets)) {
118139
await assertTargetExists(target);

0 commit comments

Comments
 (0)