Files
bun.sh/test/js/bun/shell/throw.test.ts
Zack Radisic 2b56451a11 Shell changes/fixes (#8846)
* Fix #8403

* Throw on error by default

* Add the shell promise utilities to `ShellOutput` and `ShellError`

* Fix tests

* [autofix.ci] apply automated fixes

* Fix memleak

* [autofix.ci] apply automated fixes

* Woops

* `Bun.gc(true)` in fd leak test

* fd leak test should check if `fd <= baseline`

* wtf

* oob check

* [autofix.ci] apply automated fixes

* Fix double free

* Fix #8550

* increase mem threshold for linux

* Requested changes and make not throw on by default

* [autofix.ci] apply automated fixes

* more requested changes

* Do destructuring in function definition

* delete

* Change shell output test to enable throwing

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-02-16 05:01:55 -08:00

51 lines
1.1 KiB
TypeScript

import { $ } from "bun";
import { beforeAll, describe, test, expect } from "bun:test";
beforeAll(() => {
$.nothrow();
});
describe("throw", () => {
test("enabled globally", async () => {
$.throws(true);
let e;
try {
await $`ls ksjflkjfksjdflksdjflksdf`;
expect("Woops").toBe("Should have thrown");
} catch (err) {
e = err;
}
expect(e).toBeDefined();
});
test("enabled locally", async () => {
let e;
try {
await $`ls ksjflkjfksjdflksdjflksdf`.throws(true);
expect("Woops").toBe("Should have thrown");
} catch (err) {
e = err;
}
expect(e).toBeDefined();
});
test("disable globally", async () => {
$.throws(true);
$.nothrow();
try {
await $`ls ksjflkjfksjdflksdjflksdf`;
} catch (err) {
expect("Woops").toBe("Should not have thrown");
}
});
test("disable locally", async () => {
$.throws(true);
try {
await $`ls ksjflkjfksjdflksdjflksdf`.nothrow();
} catch (err) {
expect("Woops").toBe("Should not have thrown");
}
});
});