-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0daac0
commit 52fecf9
Showing
3 changed files
with
52 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,54 @@ | ||
import { $ } from "bun"; | ||
import { bunExe, createTestBuilder } from "./test_builder"; | ||
import { bunEnv } from "harness"; | ||
const TestBuilder = createTestBuilder(import.meta.path); | ||
|
||
test("default throw on command failure", async () => { | ||
try { | ||
await $`echo hi; ls oogabooga`.quiet(); | ||
expect.unreachable(); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(Error); | ||
expect(e.exitCode).toBe(1); | ||
expect(e.message).toBe("Failed with exit code 1"); | ||
expect(e.stdout.toString("utf-8")).toBe("hi\n"); | ||
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\n"); | ||
} | ||
// Run in a subproc because other tests may change the value of $.throws | ||
const code = /* ts */ ` | ||
import { $ } from "bun"; | ||
import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | ||
test('test', async () => { | ||
try { | ||
await $\`echo hi; ls oogabooga\`.quiet(); | ||
expect.unreachable(); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(Error); | ||
expect(e.exitCode).toBe(1); | ||
expect(e.message).toBe("Failed with exit code 1"); | ||
expect(e.stdout.toString("utf-8")).toBe("hi\\n"); | ||
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\\n"); | ||
} | ||
}) | ||
`; | ||
|
||
await TestBuilder.command`echo ${code} > index.test.ts; ${bunExe()} test index.test.ts` | ||
.ensureTempDir() | ||
.stderr(s => s.includes("1 pass")) | ||
.env(bunEnv) | ||
.run(); | ||
}); | ||
|
||
test("ShellError has .text()", async () => { | ||
try { | ||
await $`ls oogabooga`.quiet(); | ||
expect.unreachable(); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(Error); | ||
expect(e.exitCode).toBe(1); | ||
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\n"); | ||
} | ||
// Run in a subproc because other tests may change the value of $.throws | ||
const code = /* ts */ ` | ||
import { $ } from "bun"; | ||
import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | ||
test('test', async () => { | ||
try { | ||
await $\`ls oogabooga\`.quiet(); | ||
expect.unreachable(); | ||
} catch (e: any) { | ||
expect(e).toBeInstanceOf(Error); | ||
expect(e.exitCode).toBe(1); | ||
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\\n"); | ||
} | ||
}) | ||
`; | ||
|
||
await TestBuilder.command`echo ${code} > index.test.ts; ${bunExe()} test index.test.ts` | ||
.ensureTempDir() | ||
.stderr(s => s.includes("1 pass")) | ||
.env(bunEnv) | ||
.run(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters