test(extension): persist timezone subprocess results
This commit is contained in:
1 parent
eaf68ef3d9
commit
e8c35e0556
1 file changed
+13
-3
@@ -1,5 +1,8 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
// Separate processes ensure each runtime actually starts in the selected system timezone.
|
||||
test("clip metadata uses the system timezone across offsets, year boundaries and DST", () => {
|
||||
@@ -8,8 +11,15 @@ test("clip metadata uses the system timezone across offsets, year boundaries and
|
||||
"Asia/Shanghai": ["2023-12-13 13:25:31", "2024-05-17 01:11:58", "2022-06-18 11:47:48", "2023-12-13 15:55:31", "2023-12-14 00:55:31", "2024-01-01 00:15:31", "2024-03-10 14:59:59", "2024-03-10 15:00:00"],
|
||||
"America/New_York": ["2023-12-13 00:25:31", "2024-05-16 13:11:58", "2022-06-17 23:47:48", "2023-12-13 02:55:31", "2023-12-13 11:55:31", "2023-12-31 11:15:31", "2024-03-10 01:59:59", "2024-03-10 03:00:00"],
|
||||
};
|
||||
for (const [timezone, result] of Object.entries(expected)) {
|
||||
const output = execFileSync(process.execPath, ["-e", `import { clipDateTimeText } from './src/clip-time.ts'; console.log(JSON.stringify(${JSON.stringify(values)}.map(clipDateTimeText)));`], { cwd: import.meta.dir, env: { ...process.env, TZ: timezone }, encoding: "utf8" });
|
||||
expect(JSON.parse(output)).toEqual(result);
|
||||
// Persist child results so this test does not depend on Bun test subprocess stdout capture.
|
||||
const directory = mkdtempSync(join(tmpdir(), "edgeever-clip-time-"));
|
||||
try {
|
||||
for (const [timezone, result] of Object.entries(expected)) {
|
||||
const outputPath = join(directory, "result.json");
|
||||
execFileSync(process.execPath, ["-e", `import { writeFileSync } from 'node:fs'; import { clipDateTimeText } from './src/clip-time.ts'; writeFileSync(${JSON.stringify(outputPath)}, JSON.stringify(${JSON.stringify(values)}.map(clipDateTimeText)));`], { cwd: import.meta.dir, env: { ...process.env, TZ: timezone } });
|
||||
expect(JSON.parse(readFileSync(outputPath, "utf8"))).toEqual(result);
|
||||
}
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user