Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions tests/handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand All @@ -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' } };
Expand Down
Loading