diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/changelog.md b/changelog.md index a0d173c..defd9f7 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,15 @@ --- +## [0.1.2] 2022-03-28 + +### Added + +- Added support for function generated mocks +- Added support for accepting cli input for function generated mocks + + + ## [0.1.0] 2022-03-27 ### Added diff --git a/readme.md b/readme.md index 57bec56..bc5d5f3 100644 --- a/readme.md +++ b/readme.md @@ -64,6 +64,9 @@ module.exports = { 'background-task': { 'my-first-mock': { /* payload */ }, 'another-mock': { /* payload */ }, + 'function-mock': (id) => { + return { /* payload */ } + } } }, queues: { diff --git a/src/index.js b/src/index.js index 9ea3129..de00b20 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,7 @@ module.exports = { let { cwd, preferences } = inv._project let jsonMocks = join(cwd, 'sandbox-invoke-mocks.json') let jsMocks = join(cwd, 'sandbox-invoke-mocks.js') + let inputPromptOpen = false let pragmas = [ 'events', 'queues', 'scheduled', 'tables-streams' ] let prefs = preferences?.sandbox?.invoker @@ -45,7 +46,7 @@ module.exports = { strong: colors.white, } } - if (input === 'i') { + if (input === 'i' && !inputPromptOpen) { if (Object.keys(events).length === 1) { let none = 'No Lambdas found to invoke' if (pragmas.length) update.status(none, `Using the following pragmas: @${pragmas.join(', @')}`) @@ -91,6 +92,21 @@ module.exports = { }, options) mockName = selection.mock userPayload = mocks[pragma][name][mockName] || {} + + if (typeof userPayload === 'function') { + inputPromptOpen = true + let { mockinput } = await prompt( + { + type: 'input', + name: 'mockinput', + message: 'What input to use for mock function?', + }, + options + ) + inputPromptOpen = false + let mockInputArgs = mockinput.split(',') + userPayload = userPayload(...mockInputArgs) + } } let payload