diff --git a/packages/runtime/test/string.test.ts b/packages/runtime/test/string.test.ts index b168fa9a4..c65ca88b3 100644 --- a/packages/runtime/test/string.test.ts +++ b/packages/runtime/test/string.test.ts @@ -1,5 +1,5 @@ import { execFile } from "node:child_process"; -import { mkdir } from "node:fs/promises"; +import { mkdir, readFile } from "node:fs/promises"; import { join } from "node:path"; import { promisify } from "node:util"; import { beforeAll, expect, test } from "vitest"; @@ -33,8 +33,10 @@ beforeAll(async () => { ]); }); -// Runs against the committed case file (generated once from Node via -// gen-string-cases.mjs — see that file to regenerate). Covers UTF-16 +// Runs against the committed case file generated from Node via +// gen-string-cases.mjs. The test below also verifies the checked-in oracle +// against the generator, so an accidental stale result cannot be masked by +// the platform-specific native-runtime allowlist. Covers UTF-16 // length/charCodeAt/indexOf/includes/startsWith/endsWith/slice/repeat/ // trim/trimStart/trimEnd/split/padStart/padEnd/charAt plus parseInt over // ASCII, Latin-1, CJK, astral, and combining-mark strings, including the @@ -63,6 +65,17 @@ const LINUX_PARSEINT_ULP: ReadonlyMap = new Map([ ], ]); +test("committed string oracle matches Node", async () => { + const caseFile = join(testDir, "string-cases.txt"); + const [{ stdout }, committed] = await Promise.all([ + execFileAsync(process.execPath, [join(testDir, "gen-string-cases.mjs")], { + maxBuffer: 2 * 1024 * 1024, + }), + readFile(caseFile, "utf8"), + ]); + expect(committed).toBe(stdout); +}); + test("string methods match Node on committed oracle cases", async () => { const r = await execFileAsync(bin, [join(testDir, "string-cases.txt")]).then( (v) => ({ stderr: v.stderr }),