Spaces:
Sleeping
Sleeping
File size: 1,262 Bytes
5743bc2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import path from "node:path";
import { fileURLToPath } from "node:url";
import { rm, mkdir } from "node:fs/promises";
import { spawn } from "node:child_process";
import { build as esbuild } from "esbuild";
const packageDir = path.dirname(fileURLToPath(import.meta.url));
const apiDir = path.resolve(packageDir, "..");
const outDir = path.resolve(apiDir, ".test-dist");
const entryFile = path.resolve(apiDir, "tests/logic.test.ts");
const bundledFile = path.resolve(outDir, "logic.test.mjs");
await rm(outDir, { recursive: true, force: true });
await mkdir(outDir, { recursive: true });
await esbuild({
entryPoints: [entryFile],
outfile: bundledFile,
platform: "node",
bundle: true,
format: "esm",
sourcemap: "inline",
logLevel: "info",
banner: {
js: `import { createRequire as __bannerCrReq } from 'node:module';
globalThis.require = __bannerCrReq(import.meta.url);`,
},
});
await new Promise((resolve, reject) => {
const child = spawn(process.execPath, ["--test", bundledFile], {
stdio: "inherit",
cwd: apiDir,
});
child.on("exit", (code) => {
if (code === 0) {
resolve();
return;
}
reject(new Error(`API logic tests failed with exit code ${code ?? -1}`));
});
child.on("error", reject);
});
|