-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (26 loc) · 1.15 KB
/
index.js
File metadata and controls
32 lines (26 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import path from 'path'
import test from 'ava'
import td from '../helpers/testdouble'
const funcName = 'foo'
const environment = 'development'
const handler = 'handler'
const config = { Handler: `index.${handler}` }
const events = ['event']
const lambdaFunc = td.object([handler])
td.when(lambdaFunc[handler](td.matchers.anything(), td.matchers.isA(Object))).thenCallback(null, 'bar')
const load = td.replace('../../src/util/load')
load.distPath = async (joinPath) => joinPath ? path.join('dist', joinPath) : 'dist'
td.when(load.funcs(funcName)).thenResolve([funcName])
td.when(load.lambdaConfig(funcName, environment)).thenResolve(config)
td.when(load.events(funcName, td.matchers.anything())).thenResolve(events)
const requireProject = td.replace('../../src/util/require-project')
td.when(requireProject(td.matchers.contains(`functions/${funcName}`))).thenReturn(lambdaFunc)
test.before(() => {
return require('../../src/run/index')({ pattern: funcName, build: false })
})
test('Calls the function', () => {
td.verify(lambdaFunc[handler](), { ignoreExtraArgs: true })
})
test('Loads event', () => {
td.verify(requireProject(td.matchers.contains('events')))
})