aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-03-22 15:01:01 -0700
committerGravatar GitHub <noreply@github.com> 2023-03-22 15:01:01 -0700
commita5f92224b586289fc72f0abdb68b08eef9f017db (patch)
tree6092397858776820b431b0dffa635d8bc3b3185e /test/js
parent2bdaa81b1c2325687c5115b4e97627533cb3646b (diff)
downloadbun-a5f92224b586289fc72f0abdb68b08eef9f017db.tar.gz
bun-a5f92224b586289fc72f0abdb68b08eef9f017db.tar.zst
bun-a5f92224b586289fc72f0abdb68b08eef9f017db.zip
Fix types (#2453)
* WIP * WIP * WIP * WIP * Improve typechecking in type files * Fix typechecking * Update * Update submodule * CI for typechecking * Add ci * Update commands * Format after build * Dont use bunx * Rename job * Use nodemodules prettier * Update workflow * Use symlink * Debug * Debug * Clean up and rename jobs
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/dns/resolve-dns.test.ts8
-rw-r--r--test/js/bun/http/bun-server.test.ts1
-rw-r--r--test/js/bun/http/serve.leak.ts3
-rw-r--r--test/js/bun/http/serve.test.ts18
-rw-r--r--test/js/bun/net/socket.test.ts7
-rw-r--r--test/js/bun/plugin/plugins.test.ts10
-rw-r--r--test/js/bun/spawn/spawn-streaming-stdin.test.ts10
-rw-r--r--test/js/bun/spawn/spawn-streaming-stdout.test.ts4
-rw-r--r--test/js/bun/spawn/spawn.test.ts2
-rw-r--r--test/js/bun/stream/direct-readable-stream.test.tsx6
-rw-r--r--test/js/bun/test/snapshot-tests/bun-snapshots.test.ts6
-rw-r--r--test/js/bun/test/snapshot-tests/existing-snapshots.test.ts2
-rw-r--r--test/js/bun/test/snapshot-tests/new-snapshot.test.ts2
-rw-r--r--test/js/bun/test/snapshot-tests/new-snapshot.ts1
-rw-r--r--test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts2
-rw-r--r--test/js/bun/test/snapshot-tests/snapshots/more.test.ts1
-rw-r--r--test/js/bun/test/snapshot-tests/snapshots/moremore.test.ts10
-rw-r--r--test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts9
-rw-r--r--test/js/bun/test/test-test.test.ts1
-rw-r--r--test/js/bun/util/filesink.test.ts4
-rw-r--r--test/js/bun/util/filesystem_router.test.ts62
-rw-r--r--test/js/bun/util/sleepSync.test.ts12
-rw-r--r--test/js/bun/util/which.test.ts2
-rw-r--r--test/js/bun/websocket/websocket-server.test.ts23
-rw-r--r--test/js/node/child_process/child_process.test.ts18
-rw-r--r--test/js/node/crypto/crypto-scrypt.test.ts (renamed from test/js/node/crypto/crypto-scrypt.test.js)2
-rw-r--r--test/js/node/crypto/crypto.test.ts (renamed from test/js/node/crypto/crypto.test.js)0
-rw-r--r--test/js/node/events/event-emitter.test.ts7
-rw-r--r--test/js/node/fs/fs.test.ts8
-rw-r--r--test/js/node/harness.ts24
-rw-r--r--test/js/node/http/node-http.fixme.ts3
-rw-r--r--test/js/node/net/node-net-server.test.ts20
-rw-r--r--test/js/node/net/node-net.test.ts80
-rw-r--r--test/js/node/readline/readline.node.test.ts2
-rw-r--r--test/js/node/readline/readline_promises.node.test.ts3
-rw-r--r--test/js/node/stream/bufferlist.test.ts21
-rw-r--r--test/js/node/stream/node-stream-uint8array.test.ts9
-rw-r--r--test/js/third_party/body-parser/express-body-parser-test.test.ts3
-rw-r--r--test/js/third_party/napi_create_external/napi-create-external.test.ts3
-rw-r--r--test/js/web/crypto/web-crypto.test.ts6
-rw-r--r--test/js/web/fetch/body.test.ts2
-rw-r--r--test/js/web/fetch/fetch-gzip.test.ts17
-rw-r--r--test/js/web/fetch/fetch.test.ts35
-rw-r--r--test/js/web/html/FormData.test.ts22
44 files changed, 302 insertions, 189 deletions
diff --git a/test/js/bun/dns/resolve-dns.test.ts b/test/js/bun/dns/resolve-dns.test.ts
index 52534da13..87d666616 100644
--- a/test/js/bun/dns/resolve-dns.test.ts
+++ b/test/js/bun/dns/resolve-dns.test.ts
@@ -3,7 +3,11 @@ import { describe, expect, it, test } from "bun:test";
import { withoutAggressiveGC } from "harness";
describe("dns.lookup", () => {
- const backends = [process.platform === "darwin" ? "system" : undefined, "libc", "c-ares"].filter(Boolean);
+ const backends = [process.platform === "darwin" ? "system" : undefined, "libc", "c-ares"].filter(x => !!x) as (
+ | "system"
+ | "libc"
+ | "c-ares"
+ )[];
for (let backend of backends) {
it(backend + " parallell x 10", async () => {
const promises = [];
@@ -37,7 +41,7 @@ describe("dns.lookup", () => {
try {
await dns.lookup("yololololololo1234567.com", { backend });
throw 42;
- } catch (e) {
+ } catch (e: any) {
expect(typeof e).not.toBe("number");
expect(e.code).toBe("DNS_ENOTFOUND");
}
diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts
index d260606e8..8c87ac422 100644
--- a/test/js/bun/http/bun-server.test.ts
+++ b/test/js/bun/http/bun-server.test.ts
@@ -158,6 +158,7 @@ describe("Server", () => {
req.signal.addEventListener("abort", () => {
signalOnServer = true;
});
+
return new Response(
new ReadableStream({
async pull(controller) {
diff --git a/test/js/bun/http/serve.leak.ts b/test/js/bun/http/serve.leak.ts
index a7b8a44f6..d8711738a 100644
--- a/test/js/bun/http/serve.leak.ts
+++ b/test/js/bun/http/serve.leak.ts
@@ -1,3 +1,4 @@
+import type { Serve } from "bun";
import { heapStats } from "bun:jsc";
var prevCounts: Record<string, number>;
export default {
@@ -26,4 +27,4 @@ export default {
},
});
},
-};
+} satisfies Serve;
diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts
index c049aad1a..51d91767e 100644
--- a/test/js/bun/http/serve.test.ts
+++ b/test/js/bun/http/serve.test.ts
@@ -3,13 +3,14 @@ import { afterEach, describe, it, expect, afterAll } from "bun:test";
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";
+type Handler = (req: Request) => Response;
afterEach(() => gc(true));
const count = 200;
let port = 10000;
let server: Server | undefined;
-async function runTest({ port, ...serverOptions }: Serve<any>, test: (server: Serve<any>) => Promise<void> | void) {
+async function runTest({ port, ...serverOptions }: Serve<any>, test: (server: Server) => Promise<void> | void) {
if (server) {
server.reload({ ...serverOptions, port: 0 });
} else {
@@ -72,6 +73,7 @@ afterAll(() => {
it("should display a welcome message when the response value type is incorrect", async () => {
await runTest(
{
+ // @ts-ignore
fetch(req) {
return Symbol("invalid response type");
},
@@ -116,7 +118,7 @@ it("request.signal works in trivial case", async () => {
it("request.signal works in leaky case", async () => {
var aborty = new AbortController();
var didAbort = false;
- var leaky;
+ var leaky: Request | undefined;
await runTest(
{
async fetch(req) {
@@ -133,7 +135,7 @@ it("request.signal works in leaky case", async () => {
await Bun.sleep(1);
- leaky.signal.addEventListener("abort", () => {
+ leaky!.signal.addEventListener("abort", () => {
didAbort = true;
});
@@ -170,7 +172,7 @@ it("should work for a file", async () => {
it("request.url should log successfully", async () => {
const fixture = resolve(import.meta.dir, "./fetch.js.txt");
const textToExpect = readFileSync(fixture, "utf-8");
- var expected;
+ var expected: string;
await runTest(
{
fetch(req) {
@@ -379,7 +381,7 @@ describe("streaming", () => {
it("text from JS throws on start has error handler", async () => {
var pass = false;
- var err;
+ var err: Error;
await runTest(
{
error(e) {
@@ -758,8 +760,8 @@ describe("parallel", () => {
});
it("should support reloading", async () => {
- const first = req => new Response("first");
- const second = req => new Response("second");
+ const first: Handler = req => new Response("first");
+ const second: Handler = req => new Response("second");
await runTest(
{
fetch: first,
@@ -835,7 +837,7 @@ describe("status code text", () => {
508: "Loop Detected",
510: "Not Extended",
511: "Network Authentication Required",
- };
+ } as Record<string, string>;
for (let code in fixture) {
it(`should return ${code} ${fixture[code]}`, async () => {
diff --git a/test/js/bun/net/socket.test.ts b/test/js/bun/net/socket.test.ts
index f6b90db00..47b33d1d4 100644
--- a/test/js/bun/net/socket.test.ts
+++ b/test/js/bun/net/socket.test.ts
@@ -1,6 +1,6 @@
import { expect, it } from "bun:test";
import { bunEnv, bunExe, expectMaxObjectTypeCount } from "harness";
-import { connect, spawn } from "bun";
+import { connect, SocketHandler, spawn } from "bun";
it("should keep process alive only when active", async () => {
const { exited, stdout, stderr } = spawn({
@@ -29,10 +29,11 @@ it("should keep process alive only when active", async () => {
it("listen() should throw connection error for invalid host", () => {
expect(() => {
- const handlers = {
+ const handlers: SocketHandler = {
open(socket) {
- socket.close();
+ socket.end();
},
+ close() {},
data() {},
};
diff --git a/test/js/bun/plugin/plugins.test.ts b/test/js/bun/plugin/plugins.test.ts
index 2bac4b4d4..79213239b 100644
--- a/test/js/bun/plugin/plugins.test.ts
+++ b/test/js/bun/plugin/plugins.test.ts
@@ -3,6 +3,16 @@ import { plugin } from "bun";
import { describe, expect, it } from "bun:test";
import { resolve } from "path";
+declare global {
+ var failingObject: any;
+ var objectModuleResult: any;
+ var laterCode: any;
+ var asyncOnLoad: any;
+ var asyncObject: any;
+ var asyncfail: any;
+ var asyncret: any;
+}
+
plugin({
name: "boop beep beep",
setup(builder) {
diff --git a/test/js/bun/spawn/spawn-streaming-stdin.test.ts b/test/js/bun/spawn/spawn-streaming-stdin.test.ts
index e2d346ec8..f69e7d9b6 100644
--- a/test/js/bun/spawn/spawn-streaming-stdin.test.ts
+++ b/test/js/bun/spawn/spawn-streaming-stdin.test.ts
@@ -19,13 +19,13 @@ test("spawn can write to stdin multiple chunks", async () => {
exited = proc.exited;
var counter = 0;
var inCounter = 0;
- var chunks = [];
+ var chunks: any[] = [];
const prom = (async function () {
try {
- for await (var chunk of proc.stdout) {
+ for await (var chunk of proc.stdout!) {
chunks.push(chunk);
}
- } catch (e) {
+ } catch (e: any) {
console.log(e.stack);
throw e;
}
@@ -33,13 +33,13 @@ test("spawn can write to stdin multiple chunks", async () => {
const prom2 = (async function () {
while (true) {
- proc.stdin.write("Wrote to stdin!\n");
+ proc.stdin!.write("Wrote to stdin!\n");
inCounter++;
await new Promise(resolve => setTimeout(resolve, 8));
if (inCounter === 4) break;
}
- proc.stdin.end();
+ proc.stdin!.end();
})();
await Promise.all([prom, prom2]);
diff --git a/test/js/bun/spawn/spawn-streaming-stdout.test.ts b/test/js/bun/spawn/spawn-streaming-stdout.test.ts
index 75e36ca2c..54c1451f0 100644
--- a/test/js/bun/spawn/spawn-streaming-stdout.test.ts
+++ b/test/js/bun/spawn/spawn-streaming-stdout.test.ts
@@ -21,12 +21,12 @@ test("spawn can read from stdout multiple chunks", async () => {
var chunks = [];
let counter = 0;
try {
- for await (var chunk of proc.stdout) {
+ for await (var chunk of proc.stdout!) {
chunks.push(chunk);
counter++;
if (counter > 3) break;
}
- } catch (e) {
+ } catch (e: any) {
console.log(e.stack);
throw e;
}
diff --git a/test/js/bun/spawn/spawn.test.ts b/test/js/bun/spawn/spawn.test.ts
index 876985e66..54b890d51 100644
--- a/test/js/bun/spawn/spawn.test.ts
+++ b/test/js/bun/spawn/spawn.test.ts
@@ -1,7 +1,7 @@
import { ArrayBufferSink, readableStreamToText, spawn, spawnSync, write } from "bun";
import { describe, expect, it } from "bun:test";
import { gcTick as _gcTick, bunEnv } from "harness";
-import { rmdirSync, unlinkSync, rmSync, writeFileSync } from "node:fs";
+import { rmSync, writeFileSync } from "node:fs";
for (let [gcTick, label] of [
[_gcTick, "gcTick"],
diff --git a/test/js/bun/stream/direct-readable-stream.test.tsx b/test/js/bun/stream/direct-readable-stream.test.tsx
index 9687e4082..1accb6d29 100644
--- a/test/js/bun/stream/direct-readable-stream.test.tsx
+++ b/test/js/bun/stream/direct-readable-stream.test.tsx
@@ -5,9 +5,11 @@ import {
readableStreamToBlob,
readableStreamToText,
serve,
+ Server,
} from "bun";
import { describe, expect, it } from "bun:test";
import { expectMaxObjectTypeCount, gc } from "harness";
+// @ts-ignore
import { renderToReadableStream as renderToReadableStreamBrowser } from "react-dom/server.browser";
import { renderToReadableStream as renderToReadableStreamBun } from "react-dom/server";
import React from "react";
@@ -89,7 +91,7 @@ const fixtures = [
πŸ˜‹LπŸ˜‹lπŸ˜‹LπŸ˜‹
</>,
],
-];
+] as const;
describe("React", () => {
it("React.createContext works", () => {
@@ -243,7 +245,7 @@ describe("ReactDOM", () => {
it(`http server, ${count} requests`, async () => {
var remain = count;
await (async () => {
- let server;
+ let server!: Server;
try {
server = serve({
port: 0,
diff --git a/test/js/bun/test/snapshot-tests/bun-snapshots.test.ts b/test/js/bun/test/snapshot-tests/bun-snapshots.test.ts
index 7ed243491..a601ca556 100644
--- a/test/js/bun/test/snapshot-tests/bun-snapshots.test.ts
+++ b/test/js/bun/test/snapshot-tests/bun-snapshots.test.ts
@@ -1,3 +1,5 @@
+import { it, test, expect, describe } from "bun:test";
+
test("it will create a snapshot file if it doesn't exist", () => {
expect({ a: { b: { c: false } }, c: 2, jkfje: 99238 }).toMatchSnapshot({ a: { b: { c: expect.any(Boolean) } } });
expect({ a: { b: { c: "string" } }, c: 2, jkfje: 99238 }).toMatchSnapshot({ a: { b: { c: expect.any(String) } } });
@@ -37,6 +39,7 @@ describe("toMatchSnapshot errors", () => {
});
it("should throw if arguments are in the wrong order", () => {
expect(() => {
+ // @ts-expect-error
expect({ a: "oops" }).toMatchSnapshot("wrong spot", { a: "oops" });
}).toThrow();
expect(() => {
@@ -46,12 +49,15 @@ describe("toMatchSnapshot errors", () => {
it("should throw if expect.any() doesn't received a constructor", () => {
expect(() => {
+ // @ts-expect-error
expect({ a: 4 }).toMatchSnapshot({ a: expect.any() });
}).toThrow();
expect(() => {
+ // @ts-expect-error
expect({ a: 5 }).toMatchSnapshot({ a: expect.any(5) });
}).toThrow();
expect(() => {
+ // @ts-expect-error
expect({ a: 4 }).toMatchSnapshot({ a: expect.any("not a constructor") });
}).toThrow();
});
diff --git a/test/js/bun/test/snapshot-tests/existing-snapshots.test.ts b/test/js/bun/test/snapshot-tests/existing-snapshots.test.ts
index 30040e2f1..e09bee659 100644
--- a/test/js/bun/test/snapshot-tests/existing-snapshots.test.ts
+++ b/test/js/bun/test/snapshot-tests/existing-snapshots.test.ts
@@ -1,3 +1,5 @@
+import { it, test, expect, describe } from "bun:test";
+
test("it will work with an existing snapshot file made with bun", () => {
expect({ a: { b: { c: false } }, c: 2, jkfje: 99238 }).toMatchSnapshot({ a: { b: { c: expect.any(Boolean) } } });
expect({ a: { b: { c: "string" } }, c: 2, jkfje: 99238 }).toMatchSnapshot({ a: { b: { c: expect.any(String) } } });
diff --git a/test/js/bun/test/snapshot-tests/new-snapshot.test.ts b/test/js/bun/test/snapshot-tests/new-snapshot.test.ts
index a3a47ae82..51aa48a13 100644
--- a/test/js/bun/test/snapshot-tests/new-snapshot.test.ts
+++ b/test/js/bun/test/snapshot-tests/new-snapshot.test.ts
@@ -2,6 +2,8 @@ import fs from "fs";
import { bunExe } from "harness";
import { tmpdir } from "os";
+import { it, test, expect, describe } from "bun:test";
+
test("it will create a snapshot file and directory if they don't exist", () => {
const tempDir = tmpdir() + "/new-snapshot";
fs.rmSync(tempDir, { force: true, recursive: true });
diff --git a/test/js/bun/test/snapshot-tests/new-snapshot.ts b/test/js/bun/test/snapshot-tests/new-snapshot.ts
index 378690a32..d7f55597d 100644
--- a/test/js/bun/test/snapshot-tests/new-snapshot.ts
+++ b/test/js/bun/test/snapshot-tests/new-snapshot.ts
@@ -1,3 +1,4 @@
+import { it, test, expect, describe } from "bun:test";
test("new snapshot", () => {
expect({ b: 2 }).toMatchSnapshot();
});
diff --git a/test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts b/test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
index 6d29cf26f..6692d72d0 100644
--- a/test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
+++ b/test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
@@ -1,3 +1,5 @@
+import { it, test, expect, describe } from "bun:test";
+
test("snapshots in different directory", () => {
expect("1\b2\n3\r4").toMatchSnapshot();
expect("\r\n").toMatchSnapshot();
diff --git a/test/js/bun/test/snapshot-tests/snapshots/more.test.ts b/test/js/bun/test/snapshot-tests/snapshots/more.test.ts
index 4cf0c8a1c..0922e4756 100644
--- a/test/js/bun/test/snapshot-tests/snapshots/more.test.ts
+++ b/test/js/bun/test/snapshot-tests/snapshots/more.test.ts
@@ -1,3 +1,4 @@
+import { it, test, expect, describe } from "bun:test";
describe("d0", () => {
test("snapshot serialize edgecases", () => {
expect(1).toMatchSnapshot();
diff --git a/test/js/bun/test/snapshot-tests/snapshots/moremore.test.ts b/test/js/bun/test/snapshot-tests/snapshots/moremore.test.ts
index d3ed3da42..d54dcc6f7 100644
--- a/test/js/bun/test/snapshot-tests/snapshots/moremore.test.ts
+++ b/test/js/bun/test/snapshot-tests/snapshots/moremore.test.ts
@@ -1,22 +1,24 @@
+import { it, test, expect, describe } from "bun:test";
+
class Number2 extends Number {
- constructor(value) {
+ constructor(value: number) {
super(value);
}
}
class Number3 extends Number2 {
- constructor(value) {
+ constructor(value: number) {
super(value);
}
}
class Boolean2 extends Boolean {
- constructor(value) {
+ constructor(value: boolean) {
super(value);
}
}
class Boolean3 extends Boolean2 {
- constructor(value) {
+ constructor(value: boolean) {
super(value);
}
diff --git a/test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts b/test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts
index e5a024379..519a0169f 100644
--- a/test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts
+++ b/test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts
@@ -1,4 +1,6 @@
-function test1000000(arg1, arg218718132) {}
+import { it, test, expect, describe } from "bun:test";
+
+function test1000000(arg1: any, arg218718132: any) {}
test("most types", () => {
expect(test1000000).toMatchSnapshot("Function");
@@ -19,6 +21,7 @@ test("most types", () => {
expect([[], [], [], []]).toMatchSnapshot("Array with multiple empty arrays");
expect([1, 2, [3, 4], [4, [5, 6]], 8]).toMatchSnapshot("Array with nested arrays");
let buf = new Buffer("hello");
+ // @ts-ignore
buf.x = "yyyyyyyyyy";
expect(buf).toMatchSnapshot("Buffer with property");
expect(new Buffer("hello")).toMatchSnapshot("Buffer2");
@@ -36,7 +39,7 @@ test("most types", () => {
new Map([
[1, "eight"],
["seven", "312390840812"],
- ]),
+ ] as any),
).toMatchSnapshot("Map");
expect(new Set()).toMatchSnapshot("Set");
expect(new Set([1, 2, 3, 4, 5, 6, 7, 8, 9])).toMatchSnapshot("Set2");
@@ -78,6 +81,7 @@ test("most types", () => {
a = 1;
b = 2;
constructor() {
+ // @ts-ignore
this.c = 3;
}
d() {
@@ -87,6 +91,7 @@ test("most types", () => {
return 5;
}
set e(value) {
+ // @ts-ignore
this.f = value;
}
}
diff --git a/test/js/bun/test/test-test.test.ts b/test/js/bun/test/test-test.test.ts
index 6dc40f97c..90a305283 100644
--- a/test/js/bun/test/test-test.test.ts
+++ b/test/js/bun/test/test-test.test.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
import { spawn, spawnSync } from "bun";
import { describe, expect, it, test } from "bun:test";
import { mkdirSync, realpathSync, rmSync, writeFileSync } from "fs";
diff --git a/test/js/bun/util/filesink.test.ts b/test/js/bun/util/filesink.test.ts
index 31fd70e54..1f41e3c56 100644
--- a/test/js/bun/util/filesink.test.ts
+++ b/test/js/bun/util/filesink.test.ts
@@ -41,7 +41,7 @@ describe("FileSink", () => {
],
] as const;
- function getPath(label) {
+ function getPath(label: string) {
const path = `/tmp/bun-test-${Bun.hash(label).toString(10)}.txt`;
try {
require("fs").unlinkSync(path);
@@ -52,7 +52,7 @@ describe("FileSink", () => {
var activeFIFO: Promise<string>;
var decoder = new TextDecoder();
- function getFd(label) {
+ function getFd(label: string) {
const path = `/tmp/bun-test-${Bun.hash(label).toString(10)}.txt`;
try {
require("fs").unlinkSync(path);
diff --git a/test/js/bun/util/filesystem_router.test.ts b/test/js/bun/util/filesystem_router.test.ts
index f5ee5c936..0cdb6a4cf 100644
--- a/test/js/bun/util/filesystem_router.test.ts
+++ b/test/js/bun/util/filesystem_router.test.ts
@@ -5,7 +5,7 @@ import fs, { mkdirSync, realpathSync, rmSync } from "fs";
import { tmpdir } from "os";
const tempdir = realpathSync(tmpdir()) + "/";
-function createTree(basedir, paths) {
+function createTree(basedir: string, paths: string[]) {
for (const end of paths) {
const abs = path.join(basedir, end);
try {
@@ -16,7 +16,7 @@ function createTree(basedir, paths) {
}
}
var count = 0;
-function make(files) {
+function make(files: string[]) {
const dir = tempdir + `fs-router-test-${count++}`;
rmSync(dir, {
recursive: true,
@@ -55,7 +55,7 @@ it("should find files", () => {
});
const routes = router.routes;
- const fixture = {
+ const fixture: Record<string, string> = {
"/": `${dir}/index.tsx`,
"/[id]": `${dir}/[id].tsx`,
"/a": `${dir}/a.tsx`,
@@ -94,6 +94,7 @@ it("should handle empty dirs", () => {
});
// assert this doesn't crash
+ // @ts-ignore
expect(router.bar).toBeUndefined();
const routes = router.routes;
@@ -110,7 +111,7 @@ it("should match dynamic routes", () => {
style: "nextjs",
});
- const { name, filePath } = router.match("/posts/hello-world");
+ const { name, filePath } = router.match("/posts/hello-world")!;
expect(name).toBe("/posts/[id]");
expect(filePath).toBe(`${dir}/posts/[id].tsx`);
@@ -127,7 +128,7 @@ it(".params works on dynamic routes", () => {
const {
params: { id },
- } = router.match("/posts/hello-world");
+ } = router.match("/posts/hello-world")!;
expect(id).toBe("hello-world");
});
@@ -141,7 +142,7 @@ it("should support static routes", () => {
style: "nextjs",
});
- const { name, params, filePath } = router.match("/posts/hey");
+ const { name, params, filePath } = router.match("/posts/hey")!;
expect(name).toBe("/posts/hey");
expect(filePath).toBe(`${dir}/posts/hey.tsx`);
@@ -161,7 +162,7 @@ it("should support optional catch-all routes", () => {
}
for (let fixture of ["/posts/hey/there", "/posts/hey/there/you", "/posts/zorp/123"]) {
- const { name, params, filePath } = router.match(fixture);
+ const { name, params, filePath } = router.match(fixture)!;
expect(name).toBe("/posts/[[...id]]");
expect(filePath).toBe(`${dir}/posts/[[...id]].tsx`);
@@ -186,11 +187,14 @@ it("should support catch-all routes", () => {
});
for (let fixture of ["/posts/123", "/posts/hey", "/posts/zorp", "/posts", "/index", "/posts/"]) {
- expect(router.match(fixture)?.name).not.toBe("/posts/[...id]");
+ console.log(`matching ${fixture}`);
+ const match = router.match(fixture);
+ console.log(match);
+ expect(match?.name).not.toBe("/posts/[...id]");
}
for (let fixture of ["/posts/hey/there", "/posts/hey/there/you", "/posts/zorp/123", "/posts/wow/hey/there"]) {
- const { name, params, filePath } = router.match(fixture);
+ const { name, params, filePath } = router.match(fixture)!;
expect(name).toBe("/posts/[...id]");
expect(filePath).toBe(`${dir}/posts/[...id].tsx`);
@@ -208,7 +212,7 @@ it("should support index routes", () => {
});
for (let route of ["/", "/index"]) {
- const { name, params, filePath } = router.match(route);
+ const { name, params, filePath } = router.match(route)!;
expect(name).toBe("/");
expect(filePath).toBe(`${dir}/index.tsx`);
@@ -216,7 +220,7 @@ it("should support index routes", () => {
}
for (let route of ["/posts", "/posts/index", "/posts/"]) {
- const { name, params, filePath } = router.match(route);
+ const { name, params, filePath } = router.match(route)!;
expect(name).toBe("/posts");
expect(filePath).toBe(`${dir}/posts.tsx`);
@@ -241,7 +245,7 @@ it("should support Request", async () => {
name,
params: { id },
filePath,
- } = router.match(current);
+ } = router.match(current)!;
expect(name).toBe("/posts/[id]");
expect(filePath).toBe(`${dir}/posts/[id].tsx`);
expect(id).toBe("hello-world");
@@ -264,7 +268,13 @@ it("assetPrefix, src, and origin", async () => {
new Request({ url: "http://helloooo.com/posts/hello-world" }),
new Request({ url: "https://nextjs.org/posts/hello-world" }),
]) {
- const { name, src, filePath, checkThisDoesntCrash } = router.match(current);
+ const {
+ name,
+ src,
+ filePath,
+ // @ts-ignore
+ checkThisDoesntCrash,
+ } = router.match(current)!;
expect(name).toBe("/posts/[id]");
// check nothing is weird on the MatchedRoute object
@@ -294,8 +304,15 @@ it(".query works", () => {
{ hello: "world", second: "2", third: "3" },
],
[new URL("https://example.com/posts").href, {}],
- ]) {
- const { name, src, filePath, checkThisDoesntCrash, query } = router.match(current);
+ ] as const) {
+ const {
+ name,
+ src,
+ filePath,
+ // @ts-ignore
+ checkThisDoesntCrash,
+ query,
+ } = router.match(current)!;
expect(name).toBe("/posts");
// check nothing is weird on the MatchedRoute object
@@ -317,9 +334,9 @@ it("reload() works", () => {
origin: "https://nextjs.org",
});
- expect(router.match("/posts").name).toBe("/posts");
+ expect(router.match("/posts")!.name).toBe("/posts");
router.reload();
- expect(router.match("/posts").name).toBe("/posts");
+ expect(router.match("/posts")!.name).toBe("/posts");
});
it(".query works with dynamic routes, including params", () => {
@@ -341,8 +358,15 @@ it(".query works with dynamic routes, including params", () => {
{ id: "123", hello: "world", second: "2", third: "3" },
],
[new URL("https://example.com/posts/123").href, { id: "123" }],
- ]) {
- const { name, src, filePath, checkThisDoesntCrash, query } = router.match(current);
+ ] as const) {
+ const {
+ name,
+ src,
+ filePath,
+ // @ts-ignore
+ checkThisDoesntCrash,
+ query,
+ } = router.match(current)!;
expect(name).toBe("/posts/[id]");
// check nothing is weird on the MatchedRoute object
diff --git a/test/js/bun/util/sleepSync.test.ts b/test/js/bun/util/sleepSync.test.ts
index dd2e8818a..e4204e1d3 100644
--- a/test/js/bun/util/sleepSync.test.ts
+++ b/test/js/bun/util/sleepSync.test.ts
@@ -10,17 +10,15 @@ it("sleepSync uses milliseconds", async () => {
});
it("sleepSync with no arguments throws", async () => {
+ // @ts-expect-error
expect(() => sleepSync()).toThrow();
});
it("sleepSync with non-numbers throws", async () => {
- expect(() => sleepSync(true)).toThrow();
- expect(() => sleepSync(false)).toThrow();
- expect(() => sleepSync("hi")).toThrow();
- expect(() => sleepSync({})).toThrow();
- expect(() => sleepSync([])).toThrow();
- expect(() => sleepSync(undefined)).toThrow();
- expect(() => sleepSync(null)).toThrow();
+ const invalidValues = [true, false, "hi", {}, [], undefined, null] as any[];
+ for (const v of invalidValues) {
+ expect(() => sleepSync(v)).toThrow();
+ }
});
it("sleepSync with negative number throws", async () => {
diff --git a/test/js/bun/util/which.test.ts b/test/js/bun/util/which.test.ts
index e142e398c..3deeebd99 100644
--- a/test/js/bun/util/which.test.ts
+++ b/test/js/bun/util/which.test.ts
@@ -52,7 +52,7 @@ test("which", () => {
} catch (e) {}
});
-function writeFixture(path) {
+function writeFixture(path: string) {
var fs = require("fs");
try {
fs.unlinkSync(path);
diff --git a/test/js/bun/websocket/websocket-server.test.ts b/test/js/bun/websocket/websocket-server.test.ts
index 47554a5f6..404eca8cf 100644
--- a/test/js/bun/websocket/websocket-server.test.ts
+++ b/test/js/bun/websocket/websocket-server.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";
import { gcTick } from "harness";
-import { serve } from "bun";
+import { serve, ServerWebSocket } from "bun";
describe("websocket server", () => {
it("remoteAddress works", done => {
@@ -80,7 +80,7 @@ describe("websocket server", () => {
server.publish("all", "hello");
},
message(ws, msg) {
- if (new TextDecoder().decode(msg) !== "hello") {
+ if (new TextDecoder().decode(msg as Uint8Array) !== "hello") {
done(new Error("unexpected message"));
}
},
@@ -108,7 +108,7 @@ describe("websocket server", () => {
done();
});
- for (let method of ["publish", "publishText", "publishBinary"]) {
+ for (let method of ["publish", "publishText", "publishBinary"] as const) {
describe(method, () => {
it("in close() should work", async () => {
var count = 0;
@@ -120,7 +120,7 @@ describe("websocket server", () => {
},
message(ws, msg) {},
close(ws) {
- ws[method]("all", method === "publishBinary" ? Buffer.from("bye!") : "bye!");
+ (ws[method] as any)("all", method === "publishBinary" ? Buffer.from("bye!") : "bye!");
count++;
if (count >= 2) {
@@ -170,7 +170,7 @@ describe("websocket server", () => {
}
it("close inside open", async () => {
- var resolve;
+ var resolve: () => void;
console.trace("here");
var server = serve({
port: 0,
@@ -574,7 +574,7 @@ describe("websocket server", () => {
it("publishText()", async () => {
await new Promise<void>((resolve, reject) => {
- var websocket;
+ var websocket: WebSocket;
var server = serve({
port: 0,
websocket: {
@@ -604,7 +604,7 @@ describe("websocket server", () => {
const bytes = Buffer.from("hello");
await new Promise<void>((resolve, reject) => {
- var websocket;
+ var websocket: WebSocket;
var server = serve({
port: 0,
websocket: {
@@ -632,7 +632,7 @@ describe("websocket server", () => {
it("sendText()", async () => {
await new Promise<void>((resolve, reject) => {
- var websocket;
+ var websocket: WebSocket;
var server = serve({
port: 0,
websocket: {
@@ -660,7 +660,7 @@ describe("websocket server", () => {
it("sendBinary()", async () => {
const bytes = Buffer.from("hello");
await new Promise<void>((resolve, reject) => {
- var websocket;
+ var websocket: WebSocket;
var server = serve({
port: 0,
websocket: {
@@ -907,7 +907,10 @@ describe("websocket server", () => {
await new Promise<void>(done => {
for (var i = 0; i < connections.length; i++) {
var j = i;
- var resolve, reject, resolveConnection, rejectConnection;
+ var resolve: (_?: unknown) => void,
+ reject: (_?: unknown) => void,
+ resolveConnection: (_?: unknown) => void,
+ rejectConnection: (_?: unknown) => void;
connections[j] = new Promise((res, rej) => {
resolveConnection = res;
rejectConnection = rej;
diff --git a/test/js/node/child_process/child_process.test.ts b/test/js/node/child_process/child_process.test.ts
index 167cbd8b0..c249c6434 100644
--- a/test/js/node/child_process/child_process.test.ts
+++ b/test/js/node/child_process/child_process.test.ts
@@ -4,14 +4,14 @@ import { ChildProcess, spawn, execFile, exec, fork, spawnSync, execFileSync, exe
import { tmpdir } from "node:os";
import { promisify } from "node:util";
-const expect: typeof expect_ = (actual: unknown) => {
+const expect = ((actual: unknown) => {
gcTick();
const ret = expect_(actual);
gcTick();
return ret;
-};
+}) as typeof expect_;
-const it: typeof it_ = (label, fn) => {
+const it = ((label, fn) => {
const hasDone = fn.length === 1;
if (fn.constructor.name === "AsyncFunction" && hasDone) {
return it_(label, async done => {
@@ -38,7 +38,7 @@ const it: typeof it_ = (label, fn) => {
gcTick();
});
}
-};
+}) as typeof it_;
const debug = process.env.DEBUG ? console.log : () => {};
@@ -56,6 +56,7 @@ describe("ChildProcess.spawn()", () => {
proc.on("spawn", () => {
resolve(true);
});
+ // @ts-ignore
proc.spawn({ file: "bun", args: ["bun", "-v"] });
});
expect(result).toBe(true);
@@ -67,7 +68,7 @@ describe("ChildProcess.spawn()", () => {
proc.on("exit", () => {
resolve(true);
});
-
+ // @ts-ignore
proc.spawn({ file: "bun", args: ["bun", "-v"] });
proc.kill();
});
@@ -174,14 +175,15 @@ describe("spawn()", () => {
it("should allow us to timeout hanging processes", async () => {
const child = spawn("sleep", ["2"], { timeout: 3 });
const start = performance.now();
- let end;
+ let end: number;
await new Promise(resolve => {
child.on("exit", () => {
end = performance.now();
resolve(true);
});
});
- expect(end - start < 2000).toBe(true);
+ expect(end!).toBeDefined();
+ expect(end! - start < 2000).toBe(true);
});
it("should allow us to set env", async () => {
@@ -195,7 +197,7 @@ describe("spawn()", () => {
});
it("should allow explicit setting of argv0", async () => {
- var resolve;
+ var resolve: (_?: any) => void;
const promise = new Promise<string>(resolve1 => {
resolve = resolve1;
});
diff --git a/test/js/node/crypto/crypto-scrypt.test.js b/test/js/node/crypto/crypto-scrypt.test.ts
index 4b7412251..2330f5b85 100644
--- a/test/js/node/crypto/crypto-scrypt.test.js
+++ b/test/js/node/crypto/crypto-scrypt.test.ts
@@ -211,7 +211,7 @@ it("scrypt badargs", () => {
try {
crypto.scryptSync(...args);
expect(() => {}).toThrow();
- } catch (e) {
+ } catch (e: any) {
if (!("code" in e)) throw e;
expect(e.code).toBe(expected.code);
}
diff --git a/test/js/node/crypto/crypto.test.js b/test/js/node/crypto/crypto.test.ts
index b5b8e9286..b5b8e9286 100644
--- a/test/js/node/crypto/crypto.test.js
+++ b/test/js/node/crypto/crypto.test.ts
diff --git a/test/js/node/events/event-emitter.test.ts b/test/js/node/events/event-emitter.test.ts
index e397faaed..401ccf605 100644
--- a/test/js/node/events/event-emitter.test.ts
+++ b/test/js/node/events/event-emitter.test.ts
@@ -100,7 +100,7 @@ const waysOfCreating = [
() => {
const FakeEmitter: any = function FakeEmitter(this: any) {
EventEmitter.call(this);
- };
+ } as any;
Object.assign(FakeEmitter.prototype, EventEmitter.prototype);
Object.assign(FakeEmitter, EventEmitter);
return new FakeEmitter();
@@ -118,6 +118,7 @@ for (let create of waysOfCreating) {
var called = false;
(myEmitter as EventEmitter).once("event", function () {
called = true;
+ // @ts-ignore
expect(this).toBe(myEmitter);
});
var firstEvents = myEmitter._events;
@@ -153,8 +154,8 @@ test("EventEmitter GCs", async () => {
Object.setPrototypeOf(EventEmitterSubclass.prototype, EventEmitter.prototype);
Object.setPrototypeOf(EventEmitterSubclass, EventEmitter);
-
- var myEmitter = new (EventEmitterSubclass as any)();
+ // @ts-ignore
+ var myEmitter = new EventEmitterSubclass();
myEmitter.on("foo", () => {});
myEmitter.emit("foo");
})();
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 48abef6cb..4636d0d4b 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -1,5 +1,5 @@
-import { beforeEach, describe, expect, it } from "bun:test";
-import { gc, gcTick } from "harness";
+import { describe, expect, it } from "bun:test";
+import { gc } from "harness";
import fs, {
closeSync,
existsSync,
@@ -41,7 +41,7 @@ if (!import.meta.dir) {
import.meta.dir = ".";
}
-function mkdirForce(path) {
+function mkdirForce(path: string) {
if (!existsSync(path)) mkdirSync(path, { recursive: true });
}
@@ -368,7 +368,7 @@ describe("writeFileSync", () => {
});
});
-function triggerDOMJIT(target, fn, result) {
+function triggerDOMJIT(target: fs.Stats, fn: (..._: any[]) => any, result: any) {
for (let i = 0; i < 9999; i++) {
if (fn.apply(target) !== result) {
throw new Error("DOMJIT failed");
diff --git a/test/js/node/harness.ts b/test/js/node/harness.ts
index 9e847c649..9cea1b781 100644
--- a/test/js/node/harness.ts
+++ b/test/js/node/harness.ts
@@ -1,3 +1,4 @@
+import { AnyFunction } from "bun";
import { gcTick, hideFromStackTrace } from "harness";
import assertNode from "node:assert";
@@ -44,10 +45,20 @@ export function createTest(path: string) {
expect(true).toBe(true);
};
+ interface NodeAssert {
+ (args: any): void;
+ strictEqual: typeof strictEqual;
+ deepStrictEqual: typeof deepStrictEqual;
+ notStrictEqual: typeof notStrictEqual;
+ throws: typeof throws;
+ ok: typeof ok;
+ ifError: typeof ifError;
+ match: typeof match;
+ }
const assert = function (...args: any[]) {
// @ts-ignore
assertNode(...args);
- };
+ } as NodeAssert;
hideFromStackTrace(strictEqual);
hideFromStackTrace(notStrictEqual);
@@ -87,8 +98,8 @@ export function createTest(path: string) {
// });
// TODO: Implement this to be exact only
- function mustCall(fn?: (...args) => any, exact?: number) {
- return mustCallAtLeast(fn, exact);
+ function mustCall(fn?: (...args: any[]) => any, exact?: number) {
+ return mustCallAtLeast(fn!, exact!);
}
function closeTimers() {
@@ -114,11 +125,12 @@ export function createTest(path: string) {
}, exact);
}
- function mustCallAtLeast(fn, minimum) {
+ function mustCallAtLeast(fn: AnyFunction, minimum: number) {
return _mustCallInner(fn, minimum, "minimum");
}
- function _mustCallInner(fn, criteria = 1, field) {
+ function _mustCallInner(fn: AnyFunction, criteria = 1, field: string) {
+ // @ts-ignore
if (process._exiting) throw new Error("Cannot use common.mustCall*() in process exit handler");
if (typeof fn === "number") {
criteria = fn;
@@ -134,7 +146,7 @@ export function createTest(path: string) {
// mustCallChecks.push(context);
const done = createDone();
- const _return = (...args) => {
+ const _return = (...args: any[]) => {
try {
// @ts-ignore
const result = fn(...args);
diff --git a/test/js/node/http/node-http.fixme.ts b/test/js/node/http/node-http.fixme.ts
index 6b01f66c3..30bfab8f9 100644
--- a/test/js/node/http/node-http.fixme.ts
+++ b/test/js/node/http/node-http.fixme.ts
@@ -1,8 +1,9 @@
+// @ts-nocheck
import { createServer, request, get, Agent, globalAgent, Server } from "node:http";
import { createTest } from "node-harness";
const { describe, expect, it, beforeAll, afterAll, createDoneDotAll } = createTest(import.meta.path);
-function listen(server: any): Promise<URL> {
+function listen(server: Server): Promise<URL> {
return new Promise((resolve, reject) => {
server.listen({ port: 0 }, (err, hostname, port) => {
if (err) {
diff --git a/test/js/node/net/node-net-server.test.ts b/test/js/node/net/node-net-server.test.ts
index e8b5234e6..86887b437 100644
--- a/test/js/node/net/node-net-server.test.ts
+++ b/test/js/node/net/node-net-server.test.ts
@@ -185,7 +185,7 @@ describe("net.createServer listen", () => {
it("should receive data", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
const onData = mustCall(data => {
clearTimeout(timeout);
@@ -195,7 +195,7 @@ it("should receive data", done => {
done();
});
- const server = createServer(socket => {
+ const server = createServer((socket: any) => {
socket.on("data", onData);
});
@@ -232,7 +232,7 @@ it("should receive data", done => {
it("should call end", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
const onEnd = mustCall(() => {
clearTimeout(timeout);
@@ -240,7 +240,7 @@ it("should call end", done => {
done();
});
- const server = createServer(socket => {
+ const server = createServer((socket: any) => {
socket.on("end", onEnd);
socket.end();
});
@@ -286,7 +286,7 @@ it("should call close", done => {
it("should call connection and drop", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
const server = createServer();
let maxClients = 2;
server.maxConnections = maxClients - 1;
@@ -350,7 +350,7 @@ it("should call connection and drop", done => {
it("should call listening", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
const server = createServer();
let maxClients = 2;
server.maxConnections = maxClients - 1;
@@ -381,7 +381,7 @@ it("should call listening", done => {
it("should call error", done => {
const { mustCall, mustNotCall, closeTimers } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
const server = createServer();
let maxClients = 2;
server.maxConnections = maxClients - 1;
@@ -415,7 +415,7 @@ it("should call abort with signal", done => {
const { mustCall, mustNotCall, closeTimers } = createCallCheckCtx(done);
const controller = new AbortController();
- let timeout;
+ let timeout: number | Timer;
const server = createServer();
let maxClients = 2;
server.maxConnections = maxClients - 1;
@@ -446,9 +446,9 @@ it("should call abort with signal", done => {
it("should echo data", done => {
const { mustCall, mustNotCall, closeTimers } = createCallCheckCtx(done);
- let timeout;
+ let timeout: number | Timer;
- const server = createServer(socket => {
+ const server = createServer((socket: any) => {
socket.pipe(socket);
});
diff --git a/test/js/node/net/node-net.test.ts b/test/js/node/net/node-net.test.ts
index 02348487f..cccada5c0 100644
--- a/test/js/node/net/node-net.test.ts
+++ b/test/js/node/net/node-net.test.ts
@@ -1,3 +1,4 @@
+import { ServerWebSocket, TCPSocket, Socket as _BunSocket, TCPSocketListener } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "bun:test";
import { connect, isIP, isIPv4, isIPv6, Socket } from "net";
import { realpathSync, mkdtempSync } from "fs";
@@ -38,9 +39,9 @@ describe("net.Socket read", () => {
["Hello!", "short message"],
]) {
describe(label, () => {
- function runWithServer(cb, unix_domain_path) {
- return done => {
- function drain(socket) {
+ function runWithServer(cb: (..._: any[]) => void, unix_domain_path?: any) {
+ return (done: (_: any) => void) => {
+ function drain(socket: _BunSocket<{ message: string }>) {
const message = socket.data.message;
const written = socket.write(message);
if (written < message.length) {
@@ -50,44 +51,42 @@ describe("net.Socket read", () => {
}
}
- var server = Bun.listen(
- unix_domain_path
- ? {
- unix: join(unix_domain_path, `${unix_servers++}.sock`),
- socket: {
- open(socket) {
- socket.data.message = message;
- drain(socket);
- },
- drain,
- error(socket, err) {
- done(err);
- },
+ var server = unix_domain_path
+ ? Bun.listen({
+ unix: join(unix_domain_path, `${unix_servers++}.sock`),
+ socket: {
+ open(socket) {
+ socket.data.message = message;
+ drain(socket);
},
- data: {
- message: "",
+ drain,
+ error(socket, err) {
+ done(err);
},
- }
- : {
- hostname: "localhost",
- port: 0,
- socket: {
- open(socket) {
- socket.data.message = message;
- drain(socket);
- },
- drain,
- error(socket, err) {
- done(err);
- },
+ },
+ data: {
+ message: "",
+ },
+ })
+ : Bun.listen({
+ hostname: "localhost",
+ port: 0,
+ socket: {
+ open(socket) {
+ socket.data.message = message;
+ drain(socket);
},
- data: {
- message: "",
+ drain,
+ error(socket, err) {
+ done(err);
},
},
- );
+ data: {
+ message: "",
+ },
+ });
- function onDone(err) {
+ function onDone(err: any) {
server.stop();
done(err);
}
@@ -237,11 +236,11 @@ describe("net.Socket write", () => {
const message = "Hello World!".repeat(1024);
let port = 53213;
- function runWithServer(cb) {
- return done => {
- let server;
+ function runWithServer(cb: (..._: any[]) => void) {
+ return (done: (_?: any) => void) => {
+ let server: TCPSocketListener<unknown>;
- function close(socket) {
+ function close(socket: _BunSocket<Buffer[]>) {
expect(Buffer.concat(socket.data).toString("utf8")).toBe(message);
done();
}
@@ -273,7 +272,7 @@ describe("net.Socket write", () => {
data: [] as Buffer[],
});
- function onDone(err) {
+ function onDone(err: any) {
server.stop();
done(err);
}
@@ -334,6 +333,7 @@ describe("net.Socket write", () => {
it("should handle connection error", done => {
var data = {};
+ // @ts-ignore
connect(55555, () => {
done(new Error("Should not have connected"));
}).on("error", error => {
diff --git a/test/js/node/readline/readline.node.test.ts b/test/js/node/readline/readline.node.test.ts
index a1077a799..a21e426b0 100644
--- a/test/js/node/readline/readline.node.test.ts
+++ b/test/js/node/readline/readline.node.test.ts
@@ -1,3 +1,4 @@
+// @ts-nocheck
import readline from "node:readline";
import { Writable, PassThrough } from "node:stream";
import { EventEmitter } from "node:events";
@@ -7,6 +8,7 @@ const { beforeEach, describe, it, createDoneDotAll, createCallCheckCtx, assert }
var {
CSI,
utils: { getStringWidth, stripVTControlCharacters },
+ // @ts-ignore
} = readline[Symbol.for("__BUN_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED__")];
// ----------------------------------------------------------------------------
diff --git a/test/js/node/readline/readline_promises.node.test.ts b/test/js/node/readline/readline_promises.node.test.ts
index 8a4ac014f..a6a464225 100644
--- a/test/js/node/readline/readline_promises.node.test.ts
+++ b/test/js/node/readline/readline_promises.node.test.ts
@@ -11,7 +11,7 @@ class FakeInput extends EventEmitter {
output = "";
resume() {}
pause() {}
- write(data) {
+ write(data: any) {
this.output += data;
}
end() {}
@@ -30,6 +30,7 @@ describe("readline/promises.createInterface()", () => {
const { mustCall, mustNotCall } = createCallCheckCtx(createDone());
const fi = new FakeInput();
+ // @ts-ignore
const rli = new readlinePromises.Interface({
input: fi,
output: fi,
diff --git a/test/js/node/stream/bufferlist.test.ts b/test/js/node/stream/bufferlist.test.ts
index b8a5443ea..8ab147d7e 100644
--- a/test/js/node/stream/bufferlist.test.ts
+++ b/test/js/node/stream/bufferlist.test.ts
@@ -1,15 +1,16 @@
import { Readable } from "stream";
import { it, expect } from "bun:test";
-function makeUint8Array(str) {
+function makeUint8Array(str: string) {
return new Uint8Array(
- [].map.call(str, function (ch) {
+ [].map.call(str, function (ch: string) {
return ch.charCodeAt(0);
- }),
+ }) as number[],
);
}
it("should work with .clear()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push({})).toBeUndefined();
@@ -21,6 +22,7 @@ it("should work with .clear()", () => {
});
it("should work with .concat()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push(makeUint8Array("foo"))).toBeUndefined();
@@ -32,6 +34,7 @@ it("should work with .concat()", () => {
});
it("should fail on .concat() with invalid items", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push("foo")).toBeUndefined();
@@ -41,6 +44,7 @@ it("should fail on .concat() with invalid items", () => {
});
it("should fail on .concat() buffer overflow", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push(makeUint8Array("foo"))).toBeUndefined();
@@ -56,6 +60,7 @@ it("should fail on .concat() buffer overflow", () => {
});
it("should work with .consume() on strings", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.consume(42, true)).toBe("");
@@ -74,6 +79,7 @@ it("should work with .consume() on strings", () => {
});
it("should work with .consume() on buffers", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.consume(42, false)).toEqual(new Uint8Array());
@@ -94,6 +100,7 @@ it("should work with .consume() on buffers", () => {
});
it("should fail on .consume() with invalid items", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push("foo")).toBeUndefined();
@@ -114,6 +121,7 @@ it("should fail on .consume() with invalid items", () => {
});
it("should work with .first()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.first()).toBeUndefined();
@@ -124,6 +132,7 @@ it("should work with .first()", () => {
});
it("should work with .join()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push(42)).toBeUndefined();
@@ -137,6 +146,7 @@ it("should work with .join()", () => {
});
it("should work with .push()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
const item1 = {};
@@ -152,6 +162,7 @@ it("should work with .push()", () => {
});
it("should work with .shift()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.shift()).toBeUndefined();
@@ -163,6 +174,7 @@ it("should work with .shift()", () => {
});
it("should work with .unshift()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
const item1 = {};
@@ -183,6 +195,7 @@ it("should work with .unshift()", () => {
});
it("should work with partial .consume() followed by .first()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push("foo")).toBeUndefined();
@@ -195,6 +208,7 @@ it("should work with partial .consume() followed by .first()", () => {
});
it("should work with partial .consume() followed by .shift()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push(makeUint8Array("foo"))).toBeUndefined();
@@ -207,6 +221,7 @@ it("should work with partial .consume() followed by .shift()", () => {
});
it("should work with partial .consume() followed by .unshift()", () => {
+ // @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push(makeUint8Array("πŸ˜‹πŸ˜‹πŸ˜‹"))).toBeUndefined();
diff --git a/test/js/node/stream/node-stream-uint8array.test.ts b/test/js/node/stream/node-stream-uint8array.test.ts
index ec2e95d34..fd2759224 100644
--- a/test/js/node/stream/node-stream-uint8array.test.ts
+++ b/test/js/node/stream/node-stream-uint8array.test.ts
@@ -1,16 +1,17 @@
import { beforeEach, describe, expect, it } from "bun:test";
-import { Readable, Writable } from "stream";
+import { Readable, Writable, WritableOptions } from "stream";
const ABC = new Uint8Array([0x41, 0x42, 0x43]);
const DEF = new Uint8Array([0x44, 0x45, 0x46]);
const GHI = new Uint8Array([0x47, 0x48, 0x49]);
describe("Writable", () => {
- let called;
+ let called: number[];
- function logCall(fn, id) {
+ function logCall(fn: WritableOptions["write"], id: number) {
return function () {
called[id] = (called[id] || 0) + 1;
+ // @ts-ignore
return fn.apply(this, arguments);
};
}
@@ -56,7 +57,7 @@ describe("Writable", () => {
});
it("should handle multiple writes carried out via writev()", () => {
- let callback;
+ let callback!: () => void;
const writable = new Writable({
write: logCall((chunk, encoding, cb) => {
diff --git a/test/js/third_party/body-parser/express-body-parser-test.test.ts b/test/js/third_party/body-parser/express-body-parser-test.test.ts
index 1f95b318e..b9cd6bbac 100644
--- a/test/js/third_party/body-parser/express-body-parser-test.test.ts
+++ b/test/js/third_party/body-parser/express-body-parser-test.test.ts
@@ -1,3 +1,6 @@
+// @ts-nocheck
+// can't use @types/express or @types/body-parser because they
+// depend on @types/node which conflicts with bun-types
import { test, expect } from "bun:test";
import express, { Application, Request, Response } from "express";
import { json } from "body-parser";
diff --git a/test/js/third_party/napi_create_external/napi-create-external.test.ts b/test/js/third_party/napi_create_external/napi-create-external.test.ts
index c3fe5ad65..47025e100 100644
--- a/test/js/third_party/napi_create_external/napi-create-external.test.ts
+++ b/test/js/third_party/napi_create_external/napi-create-external.test.ts
@@ -1,9 +1,10 @@
+// @ts-nocheck
import { test, it, describe, expect } from "bun:test";
import { withoutAggressiveGC } from "harness";
import * as _ from "lodash";
function rebase(str, inBase, outBase) {
- const mapBase = b => (b === 2 ? 32 : b === 16 ? 8 : null);
+ const mapBase = (b: number) => (b === 2 ? 32 : b === 16 ? 8 : null);
const stride = mapBase(inBase);
const pad = mapBase(outBase);
if (!stride) throw new Error(`Bad inBase ${inBase}`);
diff --git a/test/js/web/crypto/web-crypto.test.ts b/test/js/web/crypto/web-crypto.test.ts
index 250282b96..b8155c3ba 100644
--- a/test/js/web/crypto/web-crypto.test.ts
+++ b/test/js/web/crypto/web-crypto.test.ts
@@ -37,7 +37,7 @@ describe("Web Crypto", () => {
});
it("should verify and sign", async () => {
- async function importKey(secret) {
+ async function importKey(secret: string) {
return await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(secret),
@@ -47,7 +47,7 @@ describe("Web Crypto", () => {
);
}
- async function signResponse(message, secret) {
+ async function signResponse(message: string, secret: string) {
const key = await importKey(secret);
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(message));
@@ -55,7 +55,7 @@ describe("Web Crypto", () => {
return btoa(String.fromCharCode(...new Uint8Array(signature)));
}
- async function verifySignature(message, signature, secret) {
+ async function verifySignature(message: string, signature: string, secret: string) {
const key = await importKey(secret);
// Convert Base64 to Uint8Array
diff --git a/test/js/web/fetch/body.test.ts b/test/js/web/fetch/body.test.ts
index fa3d4e53b..2b9b3e11d 100644
--- a/test/js/web/fetch/body.test.ts
+++ b/test/js/web/fetch/body.test.ts
@@ -245,11 +245,9 @@ for (const { body, fn } of bodyTypes) {
});
test(body.name, async () => {
for (const { string, buffer } of utf8) {
- // @ts-expect-error
expect(() => {
fn(buffer);
}).not.toThrow();
- // @ts-expect-error
expect(await fn(buffer).text()).toBe(string);
}
});
diff --git a/test/js/web/fetch/fetch-gzip.test.ts b/test/js/web/fetch/fetch-gzip.test.ts
index 91ea8de9f..076b5845b 100644
--- a/test/js/web/fetch/fetch-gzip.test.ts
+++ b/test/js/web/fetch/fetch-gzip.test.ts
@@ -1,7 +1,6 @@
-import { concatArrayBuffers } from "bun";
-import { it, describe, expect } from "bun:test";
-import fs from "fs";
-import { gc, gcTick } from "harness";
+import { concatArrayBuffers, Socket, TCPSocketListener } from "bun";
+import { it, expect } from "bun:test";
+import { gcTick } from "harness";
it("fetch() with a buffered gzip response works (one chunk)", async () => {
var server = Bun.serve({
@@ -122,9 +121,15 @@ it("fetch() with a gzip response works (one chunk, streamed, with a delay", asyn
server.stop();
});
+const arg = Bun.listen({
+ hostname: "asdf",
+ port: 1234,
+ socket: {},
+});
+
it("fetch() with a gzip response works (multiple chunks, TCP server", async done => {
const compressed = await Bun.file(import.meta.dir + "/fixture.html.gz").arrayBuffer();
- var socketToClose;
+ var socketToClose!: Socket;
const server = Bun.listen({
port: 0,
hostname: "0.0.0.0",
@@ -134,7 +139,7 @@ it("fetch() with a gzip response works (multiple chunks, TCP server", async done
var corked: any[] = [];
var cork = true;
- async function write(chunk) {
+ async function write(chunk: any) {
await new Promise<void>((resolve, reject) => {
if (cork) {
corked.push(chunk);
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts
index 1f2345f85..f723761a7 100644
--- a/test/js/web/fetch/fetch.test.ts
+++ b/test/js/web/fetch/fetch.test.ts
@@ -1,4 +1,4 @@
-import { serve, sleep } from "bun";
+import { AnyFunction, serve, ServeOptions, Server, sleep } from "bun";
import { afterAll, afterEach, beforeAll, describe, expect, it, beforeEach } from "bun:test";
import { chmodSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "fs";
import { mkfifo } from "mkfifo";
@@ -10,8 +10,8 @@ const tmp_dir = mkdtempSync(join(realpathSync(tmpdir()), "fetch.test"));
const fixture = readFileSync(join(import.meta.dir, "fetch.js.txt"), "utf8");
-let server;
-function startServer({ fetch, ...options }) {
+let server: Server;
+function startServer({ fetch, ...options }: ServeOptions) {
server = serve({
...options,
fetch,
@@ -38,7 +38,7 @@ describe("AbortSignal", () => {
return new Response("Hello");
}
if (request.url.endsWith("/stream")) {
- const reader = request.body.getReader();
+ const reader = request.body!.getReader();
const body = new ReadableStream({
async pull(controller) {
if (!reader) controller.close();
@@ -113,11 +113,11 @@ describe("AbortSignal", () => {
const controller = new AbortController();
const signal = controller.signal;
signal.addEventListener("abort", ev => {
- const target = ev.currentTarget;
+ const target = ev.currentTarget!;
expect(target).toBeDefined();
expect(target.aborted).toBe(true);
expect(target.reason).toBeDefined();
- expect(target.reason.name).toBe("AbortError");
+ expect(target.reason!.name).toBe("AbortError");
});
expect(async () => {
@@ -280,11 +280,11 @@ describe("fetch", () => {
"http://example.com",
new URL("https://example.com"),
new Request({ url: "https://example.com" }),
- { toString: () => "https://example.com" },
+ { toString: () => "https://example.com" } as string,
];
for (let url of urls) {
gc();
- let name;
+ let name: string;
if (url instanceof URL) {
name = "URL: " + url;
} else if (url instanceof Request) {
@@ -292,7 +292,7 @@ describe("fetch", () => {
} else if (url.hasOwnProperty("toString")) {
name = "Object: " + url.toString();
} else {
- name = url;
+ name = url as string;
}
it(name, async () => {
gc();
@@ -347,7 +347,7 @@ describe("fetch", () => {
fetch(req) {
return new Response(req.body);
},
- host: "localhost",
+ hostname: "localhost",
});
// POST with body
@@ -388,7 +388,7 @@ it("website with tlsextname", async () => {
await fetch("https://bun.sh", { method: "HEAD" });
});
-function testBlobInterface(blobbyConstructor, hasBlobFn?) {
+function testBlobInterface(blobbyConstructor: { (..._: any[]): any }, hasBlobFn?: boolean) {
for (let withGC of [false, true]) {
for (let jsonObject of [
{ hello: true },
@@ -534,7 +534,7 @@ describe("Bun.file", () => {
let count = 0;
testBlobInterface(data => {
const blob = new Blob([data]);
- const buffer = Bun.peek(blob.arrayBuffer());
+ const buffer = Bun.peek(blob.arrayBuffer()) as ArrayBuffer;
const path = join(tmp_dir, `tmp-${count++}.bytes`);
writeFileSync(path, buffer);
const file = Bun.file(path);
@@ -549,8 +549,8 @@ describe("Bun.file", () => {
expect(size).toBe(Infinity);
});
- function forEachMethod(fn, skip?) {
- const method = ["arrayBuffer", "text", "json"];
+ const method = ["arrayBuffer", "text", "json"] as const;
+ function forEachMethod(fn: (m: (typeof method)[number]) => any, skip?: AnyFunction) {
for (const m of method) {
(skip ? it.skip : it)(m, fn(m));
}
@@ -643,7 +643,7 @@ describe("Blob", () => {
"πŸ˜€ πŸ˜ƒ πŸ˜„ 😁 πŸ˜† πŸ˜… πŸ˜‚ 🀣 πŸ₯² ☺️ 😊 πŸ˜‡ πŸ™‚ πŸ™ƒ πŸ˜‰ 😌 😍 πŸ₯° 😘 πŸ˜— πŸ˜™ 😚 πŸ˜‹ πŸ˜› 😝 😜 πŸ€ͺ 🀨 🧐 πŸ€“ 😎 πŸ₯Έ 🀩 πŸ₯³",
),
],
- ];
+ ] as any[];
var expected = [
"123456",
@@ -721,7 +721,7 @@ describe("Blob", () => {
const input =
Constructor === Blob ? [data] : Constructor === Request ? { body: data, url: "http://example.com" } : data;
if (withGC) gc();
- const blob = new Constructor(input);
+ const blob = new Constructor(input as any);
if (withGC) gc();
const out = await blob.arrayBuffer();
if (withGC) gc();
@@ -1101,12 +1101,14 @@ it("body nullable", async () => {
});
it("Request({}) throws", async () => {
+ // @ts-expect-error
expect(() => new Request({})).toThrow();
});
it("Request({toString() { throw 'wat'; } }) throws", async () => {
expect(
() =>
+ // @ts-expect-error
new Request({
toString() {
throw "wat";
@@ -1123,6 +1125,5 @@ it("should not be able to parse json from empty body", () => {
it("#874", () => {
expect(new Request(new Request("https://example.com"), {}).url).toBe("https://example.com");
expect(new Request(new Request("https://example.com")).url).toBe("https://example.com");
- // @ts-expect-error
expect(new Request({ url: "https://example.com" }).url).toBe("https://example.com");
});
diff --git a/test/js/web/html/FormData.test.ts b/test/js/web/html/FormData.test.ts
index edefe8a53..af2871b10 100644
--- a/test/js/web/html/FormData.test.ts
+++ b/test/js/web/html/FormData.test.ts
@@ -1,7 +1,9 @@
import { afterAll, beforeAll, describe, expect, it, test } from "bun:test";
import fs, { chmodSync, unlinkSync } from "fs";
+import { gc, withoutAggressiveGC } from "harness";
import { mkfifo } from "mkfifo";
-import { gc, withoutAggressiveGC } from "../../gc";
+
+gc;
describe("FormData", () => {
it("should be able to append a string", () => {
@@ -14,14 +16,14 @@ describe("FormData", () => {
it("should be able to append a Blob", async () => {
const formData = new FormData();
formData.append("foo", new Blob(["bar"]));
- expect(await formData.get("foo")!.text()).toBe("bar");
+ expect(await ((await formData.get("foo")) as Blob)!.text()).toBe("bar");
expect(formData.getAll("foo")[0] instanceof Blob).toBe(true);
});
it("should be able to set a Blob", async () => {
const formData = new FormData();
formData.set("foo", new Blob(["bar"]));
- expect(await formData.get("foo")!.text()).toBe("bar");
+ expect(await ((await formData.get("foo")) as Blob).text()).toBe("bar");
expect(formData.getAll("foo")[0] instanceof Blob).toBe(true);
});
@@ -135,8 +137,8 @@ describe("FormData", () => {
C === Response ? new Response(body, { headers }) : new Request({ headers, body, url: "http://hello.com" });
const formData = await response.formData();
expect(formData instanceof FormData).toBe(true);
- const entry = {};
- const expected = Object.assign({}, expected_);
+ const entry: { [k: string]: any } = {};
+ const expected: { [k: string]: any } = Object.assign({}, expected_);
for (const key of formData.keys()) {
const values = formData.getAll(key);
@@ -180,7 +182,7 @@ describe("FormData", () => {
const b = bValues[i];
if (a instanceof Blob) {
expect(b instanceof Blob).toBe(true);
- expect(await a.text()).toBe(await b.text());
+ expect(await a.text()).toBe(await (b as Blob).text());
} else {
expect(a).toBe(b);
}
@@ -200,7 +202,7 @@ describe("FormData", () => {
const b = bValues[i];
if (c instanceof Blob) {
expect(b instanceof Blob).toBe(true);
- expect(await c.text()).toBe(await b.text());
+ expect(await c.text()).toBe(await (b as Blob).text());
} else {
expect(c).toBe(b);
}
@@ -219,7 +221,7 @@ describe("FormData", () => {
try {
await response.formData();
throw "should have thrown";
- } catch (e) {
+ } catch (e: any) {
expect(typeof e.message).toBe("string");
}
});
@@ -233,7 +235,7 @@ describe("FormData", () => {
try {
await response.formData();
throw "should have thrown";
- } catch (e) {
+ } catch (e: any) {
expect(typeof e.message).toBe("string");
}
});
@@ -247,7 +249,7 @@ describe("FormData", () => {
try {
await response.formData();
throw "should have thrown";
- } catch (e) {
+ } catch (e: any) {
expect(typeof e.message).toBe("string");
}
});