diff --git a/index.mjs b/index.mjs index 7d24d34..1fb8f43 100644 --- a/index.mjs +++ b/index.mjs @@ -6,12 +6,11 @@ * under the `handlers/` directory. */ import { logDebug } from './logger.js'; -import { loadDispatchTable } from './dispatcher.js'; +import { dispatchTablePromise } from './dispatcher.js'; import handleDefault from './handlers/handleDefault.js'; -// Load dispatch configuration at startup. The promise resolves to an array of -// { check, handler } objects used during event dispatch. -const dispatchTablePromise = loadDispatchTable(); +// Dispatch configuration is loaded on module import. The promise resolves to an +// array of { check, handler } objects used during event dispatch. /** * Main Lambda entry point used by AWS. diff --git a/tests/handlers.test.js b/tests/handlers.test.js index 5a24e11..665810b 100644 --- a/tests/handlers.test.js +++ b/tests/handlers.test.js @@ -254,9 +254,9 @@ describe('handler dispatch', () => { throw new Error('boom'); }); jest.unstable_mockModule('../dispatcher.js', () => ({ - loadDispatchTable: async () => [ + dispatchTablePromise: Promise.resolve([ { check: () => true, handler: failingHandler }, - ], + ]), })); const { handler } = await import('../index.mjs'); const event = { httpMethod: 'GET', path: '/err' }; @@ -276,9 +276,9 @@ describe('handler dispatch', () => { throw new Error('boom'); }); jest.unstable_mockModule('../dispatcher.js', () => ({ - loadDispatchTable: async () => [ + dispatchTablePromise: Promise.resolve([ { check: e => e.requestContext?.routeKey, handler: failingHandler }, - ], + ]), })); const { handler } = await import('../index.mjs'); const event = { version: '2.0', requestContext: { routeKey: '$default', connectionId: '1' } };