Skip to content

Commit 983ca73

Browse files
committed
test(scripts): batch distribution import fixtures
1 parent afd1a36 commit 983ca73

1 file changed

Lines changed: 28 additions & 42 deletions

File tree

‎test/scripts/check-package-dist-imports.test.ts‎

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,27 @@ describe("check-package-dist-imports", () => {
4747
expect(result.stdout).toContain("OpenClaw package dist import closure passed.");
4848
});
4949

50-
it.each([
51-
{
52-
name: "named imports",
53-
source: 'import { value } from "./missing.js";\n',
54-
},
55-
{
56-
name: "multiline named imports",
57-
source: 'import {\n value,\n} from "./missing.js";\n',
58-
},
59-
{
60-
name: "named re-exports",
61-
source: 'export { value } from "./missing.js";\n',
62-
},
63-
{
64-
name: "multiline named re-exports",
65-
source: 'export {\n value,\n} from "./missing.js";\n',
66-
},
67-
])("rejects missing chunks in $name", ({ source }) => {
50+
it("rejects missing chunks across ESM import, re-export, and CommonJS forms", () => {
6851
const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-");
6952
mkdirSync(join(root, "dist"), { recursive: true });
70-
writeFileSync(join(root, "dist", "index.js"), source, "utf8");
53+
const sources = {
54+
"named-import.js": 'import { value } from "./missing.js";\n',
55+
"multiline-import.js": 'import {\n value,\n} from "./missing.js";\n',
56+
"named-export.js": 'export { value } from "./missing.js";\n',
57+
"multiline-export.js": 'export {\n value,\n} from "./missing.js";\n',
58+
"index.cjs": 'module.exports = require("./chunk.cjs");\n',
59+
};
60+
for (const [file, source] of Object.entries(sources)) {
61+
writeFileSync(join(root, "dist", file), source, "utf8");
62+
}
7163

7264
const result = spawnSync("node", [CHECK_SCRIPT, root], { encoding: "utf8" });
7365

7466
expect(result.status).not.toBe(0);
75-
expect(result.stderr).toContain("dist/index.js imports missing dist/missing.js");
67+
for (const file of Object.keys(sources)) {
68+
const target = file.endsWith(".cjs") ? "chunk.cjs" : "missing.js";
69+
expect(result.stderr).toContain(`dist/${file} imports missing dist/${target}`);
70+
}
7671
});
7772

7873
it("ignores import-like text inside multiline template literals", () => {
@@ -90,17 +85,23 @@ describe("check-package-dist-imports", () => {
9085
expect(result.stdout).toContain("OpenClaw package dist import closure passed.");
9186
});
9287

93-
it.each([
94-
"../../openclaw.mjs",
95-
"../../scripts/run-node.mjs",
96-
"../../dist/entry.js",
97-
"../../dist/entry.mjs",
98-
])("ignores import.meta.url probes outside packaged dist (%s)", (specifier) => {
88+
it("ignores import.meta.url probes outside packaged dist", () => {
9989
const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-");
10090
mkdirSync(join(root, "dist"), { recursive: true });
91+
const probes = [
92+
"../../openclaw.mjs",
93+
"../../scripts/run-node.mjs",
94+
"../../dist/entry.js",
95+
"../../dist/entry.mjs",
96+
];
10197
writeFileSync(
10298
join(root, "dist", "index.js"),
103-
`const candidate = new URL(${JSON.stringify(specifier)}, import.meta.url);\n`,
99+
probes
100+
.map(
101+
(specifier, index) =>
102+
`const candidate${index} = new URL(${JSON.stringify(specifier)}, import.meta.url);`,
103+
)
104+
.join("\n"),
104105
"utf8",
105106
);
106107

@@ -109,19 +110,4 @@ describe("check-package-dist-imports", () => {
109110
expect(result.status, result.stderr).toBe(0);
110111
expect(result.stdout).toContain("OpenClaw package dist import closure passed.");
111112
});
112-
113-
it("rejects missing CommonJS require chunks", () => {
114-
const root = makeTempDir(tempDirs, "openclaw-package-dist-imports-");
115-
mkdirSync(join(root, "dist"), { recursive: true });
116-
writeFileSync(
117-
join(root, "dist", "index.cjs"),
118-
'module.exports = require("./chunk.cjs");\n',
119-
"utf8",
120-
);
121-
122-
const result = spawnSync("node", [CHECK_SCRIPT, root], { encoding: "utf8" });
123-
124-
expect(result.status).not.toBe(0);
125-
expect(result.stderr).toContain("dist/index.cjs imports missing dist/chunk.cjs");
126-
});
127113
});

0 commit comments

Comments
 (0)