|
| 1 | +import TypeScriptPlugin from '../src' |
| 2 | + |
| 3 | +const createInstance = (functions: Serverless.FunctionMap, globalRuntime?: string): Serverless.Instance => ({ |
| 4 | + cli: { |
| 5 | + log: jest.fn() |
| 6 | + }, |
| 7 | + config: { |
| 8 | + servicePath: 'servicePath' |
| 9 | + }, |
| 10 | + service: { |
| 11 | + provider: { |
| 12 | + name: 'aws', |
| 13 | + runtime: globalRuntime |
| 14 | + }, |
| 15 | + package: { |
| 16 | + individually: true, |
| 17 | + include: [], |
| 18 | + exclude: [] |
| 19 | + }, |
| 20 | + functions, |
| 21 | + getAllFunctions: jest.fn() |
| 22 | + }, |
| 23 | + pluginManager: { |
| 24 | + spawn: jest.fn() |
| 25 | + } |
| 26 | +}) |
| 27 | + |
| 28 | +describe('functions', () => { |
| 29 | + const functions: Serverless.FunctionMap = { |
| 30 | + hello: { |
| 31 | + handler: 'tests/assets/hello.handler', |
| 32 | + package: { |
| 33 | + include: [], |
| 34 | + exclude: [] |
| 35 | + } |
| 36 | + }, |
| 37 | + world: { |
| 38 | + handler: 'tests/assets/world.handler', |
| 39 | + runtime: 'nodejs12.x', |
| 40 | + package: { |
| 41 | + include: [], |
| 42 | + exclude: [] |
| 43 | + }, |
| 44 | + }, |
| 45 | + js: { |
| 46 | + handler: 'tests/assets/jsfile.create', |
| 47 | + package: { |
| 48 | + include: [], |
| 49 | + exclude: [] |
| 50 | + } |
| 51 | + }, |
| 52 | + notActuallyTypescript: { |
| 53 | + handler: 'tests/assets/jsfile.create', |
| 54 | + package: { |
| 55 | + include: [], |
| 56 | + exclude: [] |
| 57 | + }, |
| 58 | + runtime: 'go1.x' |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + describe('when the provider runtime is Node', () => { |
| 63 | + it('can get filter out non node based functions', () => { |
| 64 | + const slsInstance = createInstance(functions, 'nodejs10.x') |
| 65 | + const plugin = new TypeScriptPlugin(slsInstance, {}) |
| 66 | + |
| 67 | + expect( |
| 68 | + Object.values(plugin.functions).map(fn => fn.handler), |
| 69 | + ).toEqual( |
| 70 | + [ |
| 71 | + 'tests/assets/hello.handler', |
| 72 | + 'tests/assets/world.handler', |
| 73 | + 'tests/assets/jsfile.create', |
| 74 | + ], |
| 75 | + ) |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + describe('when the provider runtime is not Node', () => { |
| 80 | + it('can get filter out non node based functions', () => { |
| 81 | + const slsInstance = createInstance(functions, 'python2.7') |
| 82 | + const plugin = new TypeScriptPlugin(slsInstance, {}) |
| 83 | + |
| 84 | + expect( |
| 85 | + Object.values(plugin.functions).map(fn => fn.handler), |
| 86 | + ).toEqual( |
| 87 | + [ |
| 88 | + 'tests/assets/world.handler', |
| 89 | + ], |
| 90 | + ) |
| 91 | + }) |
| 92 | + }) |
| 93 | + |
| 94 | + describe('when the provider runtime is undefined', () => { |
| 95 | + it('can get filter out non node based functions', () => { |
| 96 | + const slsInstance = createInstance(functions) |
| 97 | + const plugin = new TypeScriptPlugin(slsInstance, {}) |
| 98 | + |
| 99 | + expect( |
| 100 | + Object.values(plugin.functions).map(fn => fn.handler), |
| 101 | + ).toEqual( |
| 102 | + [ |
| 103 | + 'tests/assets/hello.handler', |
| 104 | + 'tests/assets/world.handler', |
| 105 | + 'tests/assets/jsfile.create', |
| 106 | + ], |
| 107 | + ) |
| 108 | + }) |
| 109 | + }) |
| 110 | +}) |
0 commit comments