diff options
-rw-r--r-- | src/bun.js/net.exports.js | 16 | ||||
-rw-r--r-- | src/bun.js/node-tls.exports.js | 17 | ||||
-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 |
5 files changed, 41 insertions, 30 deletions
diff --git a/src/bun.js/net.exports.js b/src/bun.js/net.exports.js index 14c30effc..3d15eed2b 100644 --- a/src/bun.js/net.exports.js +++ b/src/bun.js/net.exports.js @@ -531,18 +531,12 @@ const Socket = (function (InternalSocket) { ); function createConnection(port, host, connectListener) { - if (typeof host == "function") { - connectListener = host; - host = undefined; + if (typeof port === "object") { + // port is option pass Socket options and let connect handle connection options + return new Socket(port).connect(port, host, connectListener); } - var options = - typeof port == "object" - ? port - : { - host: host, - port: port, - }; - return new Socket(options).connect(options, connectListener); + // port is path or host, let connect handle this + return new Socket().connect(port, host, connectListener); } const connect = createConnection; diff --git a/src/bun.js/node-tls.exports.js b/src/bun.js/node-tls.exports.js index cbbab8e4e..d54b79089 100644 --- a/src/bun.js/node-tls.exports.js +++ b/src/bun.js/node-tls.exports.js @@ -294,19 +294,12 @@ export const CLIENT_RENEG_LIMIT = 3, DEFAULT_MIN_VERSION = "TLSv1.2", DEFAULT_MAX_VERSION = "TLSv1.3", createConnection = (port, host, connectListener) => { - if (typeof host == "function") { - connectListener = host; - host = undefined; + if (typeof port === "object") { + // port is option pass Socket options and let connect handle connection options + return new TLSSocket(port).connect(port, host, connectListener); } - var options = - typeof port == "object" - ? port - : { - host: host, - port: port, - }; - - return new TLSSocket(options).connect(options, connectListener); + // port is path or host, let connect handle this + return new TLSSocket().connect(port, host, connectListener); }, connect = createConnection; 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 = ""; |