diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cli/run/run-process-env.test.ts | 4 | ||||
-rw-r--r-- | test/harness.ts | 7 | ||||
-rw-r--r-- | test/js/node/net/node-net.test.ts | 27 |
3 files changed, 31 insertions, 7 deletions
diff --git a/test/cli/run/run-process-env.test.ts b/test/cli/run/run-process-env.test.ts index d245ff80c..8d8eb0b07 100644 --- a/test/cli/run/run-process-env.test.ts +++ b/test/cli/run/run-process-env.test.ts @@ -3,13 +3,13 @@ import { bunRunAsScript, tempDirWithFiles } from "harness"; describe("process.env", () => { test("npm_lifecycle_event", () => { - const scriptName = 'start:dev'; + const scriptName = "start:dev"; const dir = tempDirWithFiles("processenv", { "package.json": `{'scripts': {'${scriptName}': 'bun run index.ts'}}`, "index.ts": "console.log(process.env.npm_lifecycle_event);", }); - + const { stdout } = bunRunAsScript(dir, scriptName); expect(stdout).toBe(scriptName); }); diff --git a/test/harness.ts b/test/harness.ts index 72670156d..d29e4367c 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -1,8 +1,8 @@ import { gc as bunGC, unsafe } from "bun"; import { heapStats } from "bun:jsc"; import path from "path"; -import fs from 'fs'; -import os from 'os'; +import fs from "fs"; +import os from "os"; export const bunEnv: any = { ...process.env, @@ -129,8 +129,7 @@ export function bunRunAsScript(dir: string, script: string, env?: Record<string, }, }); - if (!result.success) - throw new Error(result.stderr.toString("utf8")); + if (!result.success) throw new Error(result.stderr.toString("utf8")); return { stdout: result.stdout.toString("utf8").trim(), diff --git a/test/js/node/net/node-net.test.ts b/test/js/node/net/node-net.test.ts index cccada5c0..c38a4ac1a 100644 --- a/test/js/node/net/node-net.test.ts +++ b/test/js/node/net/node-net.test.ts @@ -1,6 +1,6 @@ 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 { connect, isIP, isIPv4, isIPv6, Socket, createConnection } from "net"; import { realpathSync, mkdtempSync } from "fs"; import { tmpdir } from "os"; import { join } from "path"; @@ -178,6 +178,31 @@ describe("net.Socket read", () => { ); it( + "should work with .createConnection(path)", + runWithServer((server, drain, done) => { + var data = ""; + const socket = createConnection(server.unix) + .on("connect", () => { + expect(socket).toBeDefined(); + expect(socket.connecting).toBe(false); + }) + .setEncoding("utf8") + .on("data", chunk => { + data += chunk; + }) + .on("end", () => { + try { + expect(data).toBe(message); + done(); + } catch (e) { + server.stop(); + done(e); + } + }) + .on("error", done); + }, socket_domain), + ); + it( "should work with .connect(path)", runWithServer((server, drain, done) => { var data = ""; |