diff options
-rw-r--r-- | src/hero.mjs | 9 | ||||
-rw-r--r-- | tests/js/hero.mjs | 13 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 40d3b0d..a51d5c0 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -414,6 +414,13 @@ export const buildRoutes = (routes, globalInterceptors = []) => {} ); +export const buildTable = (routes, globalInterceptors = []) => + u.assocIn( + buildRoutes(routes, globalInterceptors), + ["interceptors"], + globalInterceptors, + ); + export const promisifyServer = (name, serverHandle, socket, pipe) => { let closePipeFn = null; return { @@ -445,7 +452,7 @@ export const buildServer = ({ pipe = `${name}.pipe`, globalInterceptors = defaultInterceptors, }) => { - const table = buildRoutes(routes, globalInterceptors); + const table = buildTable(routes, globalInterceptors); const requestListener = makeRequestListener(table); const server = http.createServer(requestListener); return promisifyServer(name, server, socket, pipe); diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 3cc5d30..3d0751c 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -36,6 +36,7 @@ import { makeReopeningPipeReader, makePipeReaderFn, buildRoutes, + buildTable, promisifyServer, buildServer, } from "../../src/hero.mjs"; @@ -1648,6 +1649,17 @@ const test_buildRoutes = async t => { }); }; +const test_buildTable = async t => { + t.start("buildTable()"); + + await t.test('we just add the "interceptors" key to what buildRoutes() gives us', () => { + assert.deepEqual( + buildTable([], [ "i1", "i2" ]), + { interceptors: [ "i1", "i2" ] }, + ); + }); +}; + const test_promisifyServer = async t => { t.start("promisifyServer()"); @@ -1728,6 +1740,7 @@ await runner.runTests([ test_actionsFn, test_lineHandlerFn, test_buildRoutes, + test_buildTable, test_rmIf, test_mkfifo, test_makeLineEmitter, |