From d064f5ba5cc2fa592c0e7566560b05e9c4ed65dc Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 24 Feb 2024 15:47:19 -0300 Subject: Normalize how modules import and name each other Also add a `defaultInterceptors` variable in `src/hero.mjs` to avoid needing to redefine it in every application. --- tests/js/hero.mjs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'tests/js/hero.mjs') diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 7b8a5cc..bc9d3d2 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -1,8 +1,8 @@ import assert from "node:assert/strict"; import http from "node:http"; -import { runTests } from "../runner.mjs"; -import { assocIn } from "../../src/utils.mjs"; +import * as runner from "../runner.mjs"; +import * as u from "../../src/utils.mjs"; import { normalizeSegments, pathToSegments, @@ -17,6 +17,7 @@ import { makeRequestListener, interceptorsFn, interceptors, + defaultInterceptors, chainInterceptors, wrapHandler, buildRoutes, @@ -274,7 +275,7 @@ const test_firstParamMatch = t => { }, }; - const tree2 = assocIn(tree1, [ "path", "param1", ":deeper", "" ], fn1); + const tree2 = u.assocIn(tree1, [ "path", "param1", ":deeper", "" ], fn1); assert.deepEqual( firstParamMatch(tree1, segments, params), @@ -298,7 +299,7 @@ const test_firstParamMatch = t => { }, }; - const tree2 = assocIn(tree1, ["user", ":aaa", ""], fn1); + const tree2 = u.assocIn(tree1, ["user", ":aaa", ""], fn1); assert.deepEqual( firstParamMatch(tree1, segments, params), @@ -1163,14 +1164,8 @@ const test_buildServer = t => { t.test("integrated application server", async () => { const socketPath = "./tests/hero-1.sock"; const pathHandler = req => ({ status: 200, body: "OK" }); - const globalInterceptors = [ - interceptors.serverError, - interceptors.contentType, - interceptors.requestId, - interceptors.logged, - ]; const routes = [ [ "GET", "/path", pathHandler ] ]; - const server = buildServer(routes, globalInterceptors); + const server = buildServer(routes, defaultInterceptors); await server.listen(socketPath); const response = await socketRequest(socketPath, "/path"); @@ -1181,7 +1176,7 @@ const test_buildServer = t => { }; -await runTests([ +await runner.runTests([ test_normalizeSegments, test_pathToSegments, test_hasPathParams, -- cgit v1.2.3