Files
bun.sh/test/cli/run/run_command.test.ts
2024-09-03 21:32:52 -07:00

33 lines
923 B
TypeScript

import { spawnSync } from "bun";
import { describe, expect, test } from "bun:test";
import { rmSync, writeFileSync } from "fs";
import { bunEnv, bunExe, bunRun, isWindows } from "harness";
let cwd: string;
describe("bun", () => {
test("should error with missing script", () => {
const { exitCode, stdout, stderr } = spawnSync({
cwd,
cmd: [bunExe(), "run", "dev"],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
expect(stdout.toString()).toBeEmpty();
expect(stderr.toString()).toMatch(/Script not found/);
expect(exitCode).toBe(1);
});
});
test.if(isWindows)("[windows] A file in drive root runs", () => {
const path = "C:\\root-file" + Math.random().toString().slice(2) + ".js";
try {
writeFileSync(path, "console.log(`PASS`);");
const { stdout } = bunRun("C:\\root-file.js", {});
expect(stdout).toBe("PASS");
} catch {
rmSync(path);
}
});