diff options
author | EuAndreh <eu@euandre.org> | 2024-03-17 17:04:47 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-17 17:04:47 -0300 |
commit | a6772f0edb76a46be0b613858d2b7493dbf9c3ef (patch) | |
tree | 25501f507b443375bc93b8a48d993fb0b9e91ed8 | |
parent | tests/js/hero.mjs: Accept a `headers` optional argument in socketRequest() (diff) | |
download | papod-a6772f0edb76a46be0b613858d2b7493dbf9c3ef.tar.gz papod-a6772f0edb76a46be0b613858d2b7493dbf9c3ef.tar.xz |
src/hero.mjs: Use name of CWD as the default name of buildServer()
-rw-r--r-- | src/hero.mjs | 6 | ||||
-rw-r--r-- | tests/js/hero.mjs | 19 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 5e4d4fa..2d1f5be 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -3,6 +3,7 @@ import child_process from "node:child_process"; import crypto from "node:crypto"; import fs from "node:fs"; import http from "node:http"; +import path from "node:path"; import process from "node:process"; import util from "node:util"; @@ -638,6 +639,7 @@ export const promisifyServer = (name, serverHandle, socket, pipe) => { let closePipeFn = null; return { ref: serverHandle, + info: () => ({ name, socket, pipe }), start: util.promisify((...args) => { assert.equal(typeof socket, "string"); assert.equal(typeof pipe, "string"); @@ -681,12 +683,12 @@ export const promisifyServer = (name, serverHandle, socket, pipe) => { }; export const buildServer = ({ - name, + name = path.basename(process.cwd()), routes = [], socket = `${name}.socket`, pipe = `${name}.pipe`, globalInterceptors = defaultInterceptors, -}) => { +} = {}) => { const table = buildTable(routes, globalInterceptors); const requestListener = makeRequestListener(table); const server = http.createServer(requestListener); diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index a35345f..1d5f910 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -1,7 +1,8 @@ -import assert from "node:assert/strict"; -import fs from "node:fs"; -import http from "node:http"; -import process from "node:process"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import http from "node:http"; +import path from "node:path"; +import process from "node:process"; import * as runner from "../runner.mjs"; import * as u from "../../src/utils.mjs"; @@ -2305,6 +2306,16 @@ const test_buildServer = async t => { await server.stop(); assert.deepEqual(response, { status: 404, body: "Not Found\n" }); + assert.deepEqual(server.info(), { name, socket, pipe }); + }); + + await t.test("default values", () => { + const name = path.basename(process.cwd()); + assert.deepEqual(buildServer().info(), { + name, + socket: `${name}.socket`, + pipe: `${name}.pipe`, + }); }); await t.test("integrated application server", async () => { |