Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(test): use owned cleanup for npm invocation fixtures

morluto5af8fe702b39
diff --git a/tests/boundary/process/packageNpmInvocation.test.ts b/tests/boundary/process/packageNpmInvocation.test.ts
index ccc5c461a..a3afae696 100644
--- a/tests/boundary/process/packageNpmInvocation.test.ts
+++ b/tests/boundary/process/packageNpmInvocation.test.ts
@@ -1,25 +1,25 @@
import { execFile } from "node:child_process";
-import { copyFile, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
-import { tmpdir } from "node:os";
+import { copyFile, mkdir, writeFile } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { promisify } from "node:util";
import { expect, it } from "vitest";
+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+
const execute = promisify(execFile);
it("runs the caller-selected npm entry through Node without rewriting its inputs", async () => {
- const root = await mkdtemp(join(tmpdir(), "rea-npm-invocation-"));
- try {
- const npmEntry = join(root, "selected npm entry.mjs");
- await writeFile(
- npmEntry,
- `process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd(), marker: process.env.REA_NPM_TEST_MARKER }));\n`,
- );
- const helper = pathToFileURL(
- resolve("scripts/lib/verify-package-core.mjs"),
- ).href;
- const program = `
+ const root = await createTestTempDirectory("rea-npm-invocation-");
+ const npmEntry = join(root, "selected npm entry.mjs");
+ await writeFile(
+ npmEntry,
+ `process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd(), marker: process.env.REA_NPM_TEST_MARKER }));\n`,
+ );
+ const helper = pathToFileURL(
+ resolve("scripts/lib/verify-package-core.mjs"),
+ ).href;
+ const program = `
const { execNpm } = await import(${JSON.stringify(helper)});
const result = await execNpm(["pack", "value with spaces"], {
cwd: ${JSON.stringify(root)},
@@ -27,19 +27,16 @@ it("runs the caller-selected npm entry through Node without rewriting its inputs
});
process.stdout.write(result.stdout);
`;
- const result = await execute(
- process.execPath,
- ["--input-type=module", "--eval", program],
- { windowsHide: true },
- );
- expect(JSON.parse(result.stdout)).toEqual({
- arguments: ["pack", "value with spaces"],
- cwd: root,
- marker: "caller-selected",
- });
- } finally {
- await rm(root, { recursive: true, force: true });
- }
+ const result = await execute(
+ process.execPath,
+ ["--input-type=module", "--eval", program],
+ { windowsHide: true },
+ );
+ expect(JSON.parse(result.stdout)).toEqual({
+ arguments: ["pack", "value with spaces"],
+ cwd: root,
+ marker: "caller-selected",
+ });
});
const windowsIt = process.platform === "win32" ? it : it.skip;
@@ -47,22 +44,21 @@ const windowsIt = process.platform === "win32" ? it : it.skip;
windowsIt(
"uses the npm entry adjacent to Node when none is selected",
async () => {
- const root = await mkdtemp(join(tmpdir(), "rea-adjacent-npm-"));
- try {
- const node = join(root, "node.exe");
- const npmEntry = join(root, "node_modules/npm/bin/npm-cli.js");
- await mkdir(dirname(npmEntry), { recursive: true });
- await Promise.all([
- copyFile(process.execPath, node),
- writeFile(
- npmEntry,
- `process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd() }));\n`,
- ),
- ]);
- const helper = pathToFileURL(
- resolve("scripts/lib/verify-package-core.mjs"),
- ).href;
- const program = `
+ const root = await createTestTempDirectory("rea-adjacent-npm-");
+ const node = join(root, "node.exe");
+ const npmEntry = join(root, "node_modules/npm/bin/npm-cli.js");
+ await mkdir(dirname(npmEntry), { recursive: true });
+ await Promise.all([
+ copyFile(process.execPath, node),
+ writeFile(
+ npmEntry,
+ `process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd() }));\n`,
+ ),
+ ]);
+ const helper = pathToFileURL(
+ resolve("scripts/lib/verify-package-core.mjs"),
+ ).href;
+ const program = `
const { execNpm } = await import(${JSON.stringify(helper)});
const environment = { ...process.env };
delete environment.npm_execpath;
@@ -72,19 +68,16 @@ windowsIt(
});
process.stdout.write(result.stdout);
`;
- const environment = { ...process.env };
- delete environment.npm_execpath;
- const result = await execute(
- node,
- ["--input-type=module", "--eval", program],
- { env: environment, windowsHide: true },
- );
- expect(JSON.parse(result.stdout)).toEqual({
- arguments: ["pack", "value with spaces"],
- cwd: root,
- });
- } finally {
- await rm(root, { recursive: true, force: true });
- }
+ const environment = { ...process.env };
+ delete environment.npm_execpath;
+ const result = await execute(
+ node,
+ ["--input-type=module", "--eval", program],
+ { env: environment, windowsHide: true },
+ );
+ expect(JSON.parse(result.stdout)).toEqual({
+ arguments: ["pack", "value with spaces"],
+ cwd: root,
+ });
},
);