diff options
author | 2022-11-09 15:40:40 -0800 | |
---|---|---|
committer | 2022-11-09 15:40:40 -0800 | |
commit | f7f1b604443c030afe29d1059b90f72c69afe081 (patch) | |
tree | 8f2397447b2a84dab02850007264b72cc565f5d6 /test/bun.js/spawn.test.ts | |
parent | da257336b0b70df8c31da647496899cf70670000 (diff) | |
download | bun-f7f1b604443c030afe29d1059b90f72c69afe081.tar.gz bun-f7f1b604443c030afe29d1059b90f72c69afe081.tar.zst bun-f7f1b604443c030afe29d1059b90f72c69afe081.zip |
Add bun-types, add typechecking, add `child_process` types (#1475)
* Add bun-types to packages
* Improve typing
* Fix types in tests
* Fix dts tests
* Run formatter
* Fix all type errors
* Add strict mode, fix type errors
* Add ffi changes
* Move workflows to root
* Add workflows
* Remove labeler
* Add child_process types
* Fix synthetic defaults issue
* Remove docs
* Move scripts
* Run prettier
* Include examples in typechecking
* captureStackTrace types
* moved captureStackTrace types to globals
* Address reviews
Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Diffstat (limited to '')
-rw-r--r-- | test/bun.js/spawn.test.ts | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts index b3ac6ae5f..f8694bfcc 100644 --- a/test/bun.js/spawn.test.ts +++ b/test/bun.js/spawn.test.ts @@ -1,12 +1,12 @@ import { readableStreamToText, spawn, spawnSync, write } from "bun"; import { describe, expect, it } from "bun:test"; -import { gcTick as _gcTick } from "gc"; +import { gcTick as _gcTick } from "./gc"; import { rmdirSync, unlinkSync, rmSync, writeFileSync } from "node:fs"; for (let [gcTick, label] of [ [_gcTick, "gcTick"], [() => {}, "no gc tick"], -]) { +] as const) { describe(label, () => { describe("spawnSync", () => { const hugeString = "hello".repeat(10000).slice(); @@ -15,7 +15,7 @@ for (let [gcTick, label] of [ const { stdout } = spawnSync(["echo", "hi"]); // stdout is a Buffer - const text = stdout.toString(); + const text = stdout!.toString(); expect(text).toBe("hi\n"); }); @@ -25,8 +25,8 @@ for (let [gcTick, label] of [ stdin: new TextEncoder().encode(hugeString), }); - expect(stdout.toString()).toBe(hugeString); - expect(stderr.byteLength).toBe(0); + expect(stdout!.toString()).toBe(hugeString); + expect(stderr!.byteLength).toBe(0); }); it("check exit code", async () => { @@ -94,7 +94,7 @@ for (let [gcTick, label] of [ it("check exit code from onExit", async () => { var exitCode1, exitCode2; - await new Promise((resolve) => { + await new Promise<void>((resolve) => { var counter = 0; spawn({ cmd: ["ls"], @@ -156,7 +156,7 @@ for (let [gcTick, label] of [ stdin: Bun.file("/tmp/out.456.txt"), }); gcTick(); - expect(await readableStreamToText(stdout)).toBe("hello there!"); + expect(await readableStreamToText(stdout!)).toBe("hello there!"); }); it("Bun.file() works as stdin and stdout", async () => { @@ -184,9 +184,10 @@ for (let [gcTick, label] of [ cmd: ["cat", "/tmp/out.txt"], stdout: "pipe", }); + gcTick(); - const text = await readableStreamToText(stdout); + const text = await readableStreamToText(stdout!); gcTick(); expect(text).toBe(hugeString); }); @@ -220,17 +221,18 @@ for (let [gcTick, label] of [ stdin: "pipe", stderr: "inherit", }); - proc.stdin.write(hugeString); - await proc.stdin.end(true); + + proc.stdin!.write(hugeString); + await proc.stdin!.end(); var text = ""; - var reader = proc.stdout.getReader(); + var reader = proc.stdout!.getReader(); var done = false; while (!done) { var { value, done } = await reader.read(); if (value) text += new TextDecoder().decode(value); if (done && text.length === 0) { reader.releaseLock(); - reader = proc.stdout.getReader(); + reader = proc.stdout!.getReader(); done = false; } } @@ -262,14 +264,14 @@ for (let [gcTick, label] of [ const fixtures = [ [helloWorld, "hello"], [huge, hugeString], - ]; + ] as const; for (const [callback, fixture] of fixtures) { describe(fixture.slice(0, 12), () => { describe("should should allow reading stdout", () => { it("before exit", async () => { const process = callback(); - const output = await readableStreamToText(process.stdout); + const output = await readableStreamToText(process.stdout!); const expected = fixture + "\n"; expect(output.length).toBe(expected.length); expect(output).toBe(expected); @@ -280,7 +282,7 @@ for (let [gcTick, label] of [ it("before exit (chunked)", async () => { const process = callback(); var output = ""; - var reader = process.stdout.getReader(); + var reader = process.stdout!.getReader(); var done = false; while (!done) { var { value, done } = await reader.read(); @@ -296,9 +298,9 @@ for (let [gcTick, label] of [ it("after exit", async () => { const process = callback(); - await process.stdin.end(); + await process.stdin!.end(); - const output = await readableStreamToText(process.stdout); + const output = await readableStreamToText(process.stdout!); const expected = fixture + "\n"; expect(output.length).toBe(expected.length); |