diff options
Diffstat (limited to 'test/js/node')
-rw-r--r-- | test/js/node/child_process/child_process.test.ts | 18 | ||||
-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.ts | 7 | ||||
-rw-r--r-- | test/js/node/fs/fs.test.ts | 8 | ||||
-rw-r--r-- | test/js/node/harness.ts | 24 | ||||
-rw-r--r-- | test/js/node/http/node-http.fixme.ts | 3 | ||||
-rw-r--r-- | test/js/node/net/node-net-server.test.ts | 20 | ||||
-rw-r--r-- | test/js/node/net/node-net.test.ts | 80 | ||||
-rw-r--r-- | test/js/node/readline/readline.node.test.ts | 2 | ||||
-rw-r--r-- | test/js/node/readline/readline_promises.node.test.ts | 3 | ||||
-rw-r--r-- | test/js/node/stream/bufferlist.test.ts | 21 | ||||
-rw-r--r-- | test/js/node/stream/node-stream-uint8array.test.ts | 9 |
13 files changed, 116 insertions, 81 deletions
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) => { |