test(extension): run capture bundle check in isolated Vite process
This commit is contained in:
1 parent
35a2bb8860
commit
2b519bfc96
1 file changed
+14
-6
@@ -1,19 +1,27 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { Script } from "node:vm";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { build } from "vite";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
test("the injected page capture is a standalone classic script", async () => {
|
||||
const outDir = await mkdtemp(join(tmpdir(), "edgeever-capture-"));
|
||||
try {
|
||||
await build({
|
||||
configFile: fileURLToPath(new URL("./vite.config.ts", import.meta.url)),
|
||||
logLevel: "silent",
|
||||
build: { outDir },
|
||||
});
|
||||
await execFileAsync(process.execPath, [
|
||||
fileURLToPath(new URL("../../node_modules/vite/bin/vite.js", import.meta.url)),
|
||||
"build",
|
||||
"--config",
|
||||
fileURLToPath(new URL("./vite.config.ts", import.meta.url)),
|
||||
"--outDir",
|
||||
outDir,
|
||||
"--logLevel",
|
||||
"silent",
|
||||
]);
|
||||
|
||||
const capture = await readFile(join(outDir, "assets/capture.js"), "utf8");
|
||||
expect(() => new Script(capture)).not.toThrow();
|
||||
|
||||
Reference in new issue
Block a user