mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
test: own temporary directories through createTestTempDirectory in src/ tests (#12725)
Give per-test temporary directories to the shared helper so Vitest removes them after the case. Keep directories whose lifetime is the assertion, or that are shared from beforeAll, on their existing cleanup. Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
1 parent
79171a4d02
commit
be14c9d475
42 files changed
+887
-1187
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
|
||||
const writeFileMock = vi.hoisted(() => vi.fn());
|
||||
const windowsWriteTransientFile = vi.hoisted(() => vi.fn());
|
||||
@@ -121,27 +121,23 @@ describe("writeJavaScriptAnalysisSourceTransfer", () => {
|
||||
return actual.writeFile(...args);
|
||||
},
|
||||
);
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-js-source-transfer-"));
|
||||
const root = await createTestTempDirectory("rea-js-source-transfer-");
|
||||
const path = join(root, "job.source");
|
||||
try {
|
||||
await writeJavaScriptAnalysisSourceTransfer(path, "source-bytes", {
|
||||
await writeJavaScriptAnalysisSourceTransfer(path, "source-bytes", {
|
||||
platform: "linux",
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe("source-bytes");
|
||||
expect(writeFileMock).toHaveBeenCalledWith(path, "source-bytes", {
|
||||
flag: "wx",
|
||||
mode: 0o600,
|
||||
signal: undefined,
|
||||
});
|
||||
expect(windowsPrivateRuntime).not.toHaveBeenCalled();
|
||||
await expect(
|
||||
writeJavaScriptAnalysisSourceTransfer(path, "again", {
|
||||
platform: "linux",
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe("source-bytes");
|
||||
expect(writeFileMock).toHaveBeenCalledWith(path, "source-bytes", {
|
||||
flag: "wx",
|
||||
mode: 0o600,
|
||||
signal: undefined,
|
||||
});
|
||||
expect(windowsPrivateRuntime).not.toHaveBeenCalled();
|
||||
await expect(
|
||||
writeJavaScriptAnalysisSourceTransfer(path, "again", {
|
||||
platform: "linux",
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "EEXIST" });
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "EEXIST" });
|
||||
});
|
||||
|
||||
it("surfaces EPERM from the POSIX exclusive create path", async () => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { createInterface } from "node:readline";
|
||||
import { expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
JAVASCRIPT_ANALYSIS_WORKER_DEFAULTS,
|
||||
javaScriptWorkerAdmissionSchema,
|
||||
@@ -23,7 +23,7 @@ const admission = (id: string) =>
|
||||
});
|
||||
|
||||
const startServer = async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-js-server-framing-"));
|
||||
const root = await createTestTempDirectory("rea-js-server-framing-");
|
||||
const serverUrl = new URL(
|
||||
"./JavaScriptAnalysisWorkerServer.ts",
|
||||
import.meta.url,
|
||||
@@ -90,7 +90,6 @@ const startServer = async () => {
|
||||
if (child.exitCode === null && child.signalCode === null) child.kill();
|
||||
await closed;
|
||||
lines.close();
|
||||
await rm(root, { recursive: true, force: true });
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user