scripts: the opencode2 and proc tests pass on Windows
unisong reported in #1206 that tests under scripts/ fail on Windows on main. Reproduced on the Windows box at origin/main (bun test scripts): 23 pass, 8 fail. - opencode2.test.mjs took the packages folder from a file URL's pathname, "/C:/…", and join made it "\C:\…", so seven imports failed ("Cannot find module"). It is fileURLToPath now. - scripts/sync-proc.mjs had the same pathname root. proc.test.mjs imports it, so the whole file failed to load (the eighth red). - With it loading, proc.test.mjs showed five more on Windows: its fake readFile matched "/fake-proc/123/stat" while proc.mjs joins with the system's separator, and the kill(pid, 0) walk's skip list (written with "/") skipped nothing, so it walked test folders and passed its 5s bound. The fake now matches join()'s path, and the walk compares "/" paths. proc.mjs itself is unchanged: it reads /proc on Linux only. Only scripts/ changes; no package's files, so no version. Run: - win-run (Windows 11) bun test scripts: 39 pass, 0 fail (origin/main: 23 pass, 8 fail). - mica-run (macOS) bun test scripts: 39 pass; node scripts/sync-proc.mjs ok, and on Windows too. Not tried: Linux (CI runs it).
This commit is contained in:
@@ -7,8 +7,11 @@
|
||||
import { afterAll, beforeAll, expect, test } from "bun:test"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const packages = new URL("../packages/", import.meta.url).pathname
|
||||
// a path, not a URL's pathname: on Windows that is "/C:/…", and
|
||||
// join made it "\C:\…", which no import finds
|
||||
const packages = fileURLToPath(new URL("../packages/", import.meta.url))
|
||||
// no request leaves these tests; fetch is put back after them, since a
|
||||
// root `bun test` runs every package's files in this one process
|
||||
const realFetch = globalThis.fetch
|
||||
|
||||
Reference in New Issue
Block a user