mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
* Move ReadFile and WriteFile to separate file * Use libuv for Bun.write() * Update windows_event_loop.zig * build * Get bun-write tests to pass. Implement Bun.write with two files. * UPdate * Update * Update failing test list * update * More * More * More * More * Mark the rest * ok * oops * Update bun-write.test.js * Update blob.zig --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dave Caruso <me@paperdave.net> Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
120 lines
3.3 KiB
TypeScript
120 lines
3.3 KiB
TypeScript
import { describe, test, expect, beforeAll } from "bun:test";
|
|
import { spawnSync } from "bun";
|
|
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
|
|
|
|
let cwd: string;
|
|
|
|
beforeAll(() => {
|
|
cwd = tempDirWithFiles("--if-present", {
|
|
"present.js": "console.log('Here!');",
|
|
"package.json": JSON.stringify({
|
|
"name": "present",
|
|
"scripts": {
|
|
"present": "echo 'Here!'",
|
|
},
|
|
}),
|
|
});
|
|
});
|
|
|
|
describe("bun", () => {
|
|
test("should error with missing script", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "notpresent"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toMatch(/Script not found/);
|
|
expect(exitCode).toBe(1);
|
|
});
|
|
test("should error with missing module", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "./notpresent.js"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toMatch(/Module not found/);
|
|
expect(exitCode).toBe(1);
|
|
});
|
|
test("should error with missing file", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "/path/to/notpresent.txt"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toMatch(/File not found/);
|
|
expect(exitCode).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("bun --if-present", () => {
|
|
test("should not error with missing script", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "--if-present", "notpresent"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toBeEmpty();
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
test("should not error with missing module", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "--if-present", "./notpresent.js"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toBeEmpty();
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
test("should not error with missing file", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "--if-present", "/path/to/notpresent.txt"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toBeEmpty();
|
|
expect(stderr.toString()).toBeEmpty();
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
test("should run present script", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "run", "present"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toMatch(/Here!/);
|
|
expect(stderr.toString()).not.toBeEmpty();
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
test("should run present module", () => {
|
|
const { exitCode, stdout, stderr } = spawnSync({
|
|
cwd,
|
|
cmd: [bunExe(), "run", "present.js"],
|
|
env: bunEnv,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(stdout.toString()).toMatch(/Here!/);
|
|
expect(stderr.toString()).toBeEmpty();
|
|
expect(exitCode).toBe(0);
|
|
});
|
|
});
|