Files
bun.sh/test/cli/run/run-cjs.test.ts
2024-05-14 20:19:35 -07:00

17 lines
553 B
TypeScript

import { expect, test } from "bun:test";
import { mkdirSync } from "fs";
import { bunEnv, bunExe, tmpdirSync } from "harness";
import { join } from "path";
test("running a commonjs module works", async () => {
const dir = tmpdirSync();
mkdirSync(dir, { recursive: true });
await Bun.write(join(dir, "index1.js"), "module.exports = 1; console.log('hello world');");
let { stdout } = Bun.spawnSync({
cmd: [bunExe(), join(dir, "index1.js")],
cwd: dir,
env: bunEnv,
});
expect(stdout.toString("utf8")).toEqual("hello world\n");
});