Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/codegen-deno/deno_scripting.harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const fs = {
};

const fsStub = {
/** Returns the in-memory `fs` entries for `path` as Dirent-like objects, or throws ENOENT. */
readdirSync: (path) => {
const entries = fs[path];
if (!entries) {
Expand All @@ -40,17 +41,24 @@ const fsStub = {
isDirectory: () => e.isDirectory,
}));
},
/** No-op stand-in; this corpus never asserts on directory creation. */
mkdirSync: () => {},
/** No-op stand-in; this corpus never asserts on file writes. */
writeFileSync: () => {},
/** No-op stand-in; this corpus never asserts on file removal. */
rmSync: () => {},
/** Returns an empty buffer; this corpus never asserts on file contents. */
readFileSync: () => new Uint8Array(),
/** Always throws ENOENT; this corpus never exercises a successful stat. */
statSync: (path) => {
const err = new Error(`stub: no such path ${path}`);
err.code = "ENOENT";
throw err;
},
};

// Intercepts the Bun-ESM prelude's lazy `node:fs` resolution so `fsStub`
// backs the emitted FS calls; delegates any other builtin to the real host.
const realGetBuiltinModule = process.getBuiltinModule?.bind(process);
process.getBuiltinModule = (name) => {
if (name === "node:fs") return fsStub;
Expand All @@ -65,6 +73,7 @@ process.getBuiltinModule = (name) => {
const realArgv = process.argv;
process.argv = ["node", "deno_scripting.harness.mjs", "alpha", "beta", "gamma"];
let lastExit = null;
/** Captures the exit code instead of terminating the harness process. */
process.exit = (code) => { lastExit = code; };

// Capture stderr writes from consoleError.
Expand Down
4 changes: 4 additions & 0 deletions tests/codegen-deno/deno_scripting_part2.harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const files = {
};

const fsStub = {
/** Returns size/isFile/isDirectory for a known path, or throws ENOENT. */
statSync: (path) => {
const e = files[path];
if (!e) {
Expand All @@ -31,6 +32,7 @@ const fsStub = {
isDirectory: () => e.kind === "dir",
};
},
/** Returns the stubbed bytes for a known file path, or throws ENOENT. */
readFileSync: (path) => {
const e = files[path];
if (!e || e.kind !== "file") {
Expand All @@ -42,6 +44,8 @@ const fsStub = {
},
};

// Intercepts the Bun-ESM prelude's lazy `node:fs` resolution so `fsStub`
// backs the emitted FS calls; delegates any other builtin to the real host.
const realGetBuiltinModule = process.getBuiltinModule?.bind(process);
process.getBuiltinModule = (name) => {
if (name === "node:fs") return fsStub;
Expand Down
2 changes: 2 additions & 0 deletions tools/run_codegen_bun_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if ! command -v bun >/dev/null 2>&1; then
fi

failures=()
# Records a check failure and echoes it as a `::error::` annotation, without
# aborting the script, so later checks still run (fail-late).
fail() {
failures+=("$1")
echo "::error::$1" >&2
Expand Down
Loading