aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-09-15 04:21:43 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-15 04:21:43 -0700
commit56c471a0052b081d01b973fc86a5d75a2373dce9 (patch)
tree28747cfdd928b3850b2691f6b0b353c7c1b00a91 /test
parent20f61b236980cf12dee0b0b80b04f605bd517581 (diff)
downloadbun-56c471a0052b081d01b973fc86a5d75a2373dce9.tar.gz
bun-56c471a0052b081d01b973fc86a5d75a2373dce9.tar.zst
bun-56c471a0052b081d01b973fc86a5d75a2373dce9.zip
Make `bun run --silent` omit `"error: "..." exited with code 1` (#5459)
* Make --silent behave as expected * Make the "tsconfig.json extends" error a debug level --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test')
-rw-r--r--test/cli/install/bun-run.test.ts90
1 files changed, 66 insertions, 24 deletions
diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts
index 6bf910951..3c12086b1 100644
--- a/test/cli/install/bun-run.test.ts
+++ b/test/cli/install/bun-run.test.ts
@@ -87,39 +87,81 @@ for (let withRun of [false, true]) {
expect(exitCode).toBe(0);
});
- it("valid tsconfig.json with invalid extends doesn't crash", async () => {
- await writeFile(
- join(run_dir, "package.json"),
- JSON.stringify({
- name: "test",
- version: "0.0.0",
- scripts: {},
- }),
- );
- await writeFile(
- join(run_dir, "tsconfig.json"),
- JSON.stringify(
- {
- extends: "!!!bad!!!",
- },
- null,
- 2,
- ),
- );
+ it("--silent omits error messages", async () => {
+ const { stdout, stderr, exitCode } = spawnSync({
+ cmd: [bunExe(), "run", "--silent", "bash", "-c", "exit 1"],
+ cwd: run_dir,
+ env: bunEnv,
+ });
- await writeFile(join(run_dir, "index.js"), "console.log('hi')");
+ expect(stderr.toString()).toBe("");
+ expect(stdout.toString()).toBe("");
+ expect(exitCode).toBe(1);
+ });
+ it("no --silent includes error messages", async () => {
const { stdout, stderr, exitCode } = spawnSync({
- cmd: [bunExe(), "--silent", withRun ? "run" : "", "./index.js"].filter(Boolean),
+ cmd: [bunExe(), "run", "bash", "-c", "exit 1"],
cwd: run_dir,
env: bunEnv,
});
- expect(stderr.toString().trim()).toContain("FileNotFound loading tsconfig.json extends");
- expect(stdout.toString()).toBe("hi\n");
- expect(exitCode).toBe(0);
+ expect(stderr.toString()).toStartWith('error: "bash" exited with code 1');
+ expect(exitCode).toBe(1);
});
+ for (let withLogLevel of [true, false]) {
+ it(
+ "valid tsconfig.json with invalid extends doesn't crash" + (withLogLevel ? " (log level debug)" : ""),
+ async () => {
+ await writeFile(
+ join(run_dir, "package.json"),
+ JSON.stringify({
+ name: "test",
+ version: "0.0.0",
+ scripts: {},
+ }),
+ );
+ if (withLogLevel)
+ await writeFile(
+ join(run_dir, "bunfig.toml"),
+ `
+logLevel = "debug"
+ `,
+ );
+
+ await writeFile(
+ join(run_dir, "tsconfig.json"),
+ JSON.stringify(
+ {
+ extends: "!!!bad!!!",
+ },
+ null,
+ 2,
+ ),
+ );
+
+ await writeFile(join(run_dir, "index.js"), "console.log('hi')");
+
+ const { stdout, stderr, exitCode } = spawnSync({
+ // TODO: figure out why -c is necessary here.
+ cmd: [bunExe(), withRun ? "run" : "", "-c=" + join(run_dir, "bunfig.toml"), "./index.js"].filter(Boolean),
+ cwd: run_dir,
+ env: bunEnv,
+ });
+ if (withLogLevel) {
+ expect(stderr.toString().trim()).toContain("FileNotFound loading tsconfig.json extends");
+ } else {
+ expect(stderr.toString().trim()).not.toContain("FileNotFound loading tsconfig.json extends");
+ }
+
+ expect(stdout.toString()).toBe("hi\n");
+ expect(exitCode).toBe(0);
+ await rm(join(run_dir, "bunfig.toml"), { force: true });
+ },
+ );
+ }
+
it("falling back to index with no package.json", async () => {
await writeFile(join(run_dir, "index.ts"), "console.log('Hello, world!');");