-
Notifications
You must be signed in to change notification settings - Fork 15
/
sls-test-utils.ts
54 lines (49 loc) · 1.31 KB
/
sls-test-utils.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { type Template } from 'cloudform'
import pino from 'pino'
// Serverless Framework provides plugins with a logger to use, so we simulate that with this:
const extras = ['levels', 'silent', 'onChild', 'trace', 'debug', 'info', 'warn', 'error', 'fatal']
const pinoLogger = pino()
export const dummyLogger = Object.fromEntries(
Object.entries(pinoLogger).filter(([key]) => !extras.includes(key))
)
export const pluginUtils = { log: dummyLogger }
export interface SlsYaml {
custom?
functions?
}
export const slsYaml: SlsYaml = {
custom: {
slicWatch: {
topicArn: 'test-topic',
enabled: true
}
},
functions: {
hello: {
}
}
}
export function createMockServerless (compiledTemplate: Template, slsConfig = slsYaml) {
return {
cli: {
log: () => { '' }
},
providers: { aws: {} },
getProvider: () => ({
naming: {
getLambdaLogicalId: (funcName: string) => {
return funcName[0].toUpperCase() + funcName.slice(1) + 'LambdaFunction'
}
}
}),
service: {
provider: {
name: 'aws',
compiledCloudFormationTemplate: compiledTemplate
},
custom: slsConfig.custom,
getAllFunctions: () => Object.keys(slsConfig.functions ?? {}),
getFunction: (funcRef) => slsConfig.functions[funcRef]
}
}
}