-
Notifications
You must be signed in to change notification settings - Fork 415
/
Copy pathprepareLocalInvoke.test.js
90 lines (75 loc) · 2.64 KB
/
prepareLocalInvoke.test.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const _ = require('lodash');
const sinon = require('sinon');
const Serverless = require('serverless');
const path = require('path');
const baseModule = require('../lib/prepareLocalInvoke');
jest.mock('../lib/utils', () => {
return {
purgeCache: jest.fn()
};
});
describe('prepareLocalInvoke', () => {
let serverless;
let module;
let sandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
serverless = new Serverless({ commands: ['print'], options: {}, serviceDir: null });
serverless.cli = {
log: jest.fn()
};
_.set(serverless, 'config.serverless.processedInput.options', {
path: './event.json'
});
sandbox.stub(process, 'chdir');
serverless.service.getFunction = jest.fn();
module = _.assign(
{
serverless,
options: {}
},
baseModule
);
});
afterEach(() => {
sandbox.restore();
});
it('should store original service path', () => {
module.serverless.service.package = {};
module.serverless.service.getFunction.mockReturnValue({ handler: 'myFuncHandler' });
module.webpackOutputPath = '.';
module.serverless.config.servicePath = './servicePath';
module.prepareLocalInvoke();
expect(module.originalServicePath).toEqual('./servicePath');
});
it('should use the function folder as cwd', () => {
module.serverless.service.package = {
individually: true
};
module.options.function = 'myFunc';
module.serverless.service.getFunction.mockReturnValue({ handler: 'myFuncHandler' });
module.webpackOutputPath = '.webpack';
module.serverless.config.servicePath = './servicePath';
module.prepareLocalInvoke();
expect(process.chdir.args[0]).toEqual([path.join('.webpack', 'myFunc')]);
});
it('should use the service folder as cwd', () => {
module.serverless.service.package = {};
module.options.function = 'myFunc';
module.serverless.service.getFunction.mockReturnValue({ handler: 'myFuncHandler' });
module.webpackOutputPath = '.webpack';
module.serverless.config.servicePath = './servicePath';
module.prepareLocalInvoke();
expect(process.chdir.args[0]).toEqual([path.join('.webpack', 'service')]);
});
it('should work without path option', () => {
module.serverless.service.package = {};
module.serverless.service.getFunction.mockReturnValue({ handler: 'myFuncHandler' });
module.webpackOutputPath = '.';
module.serverless.config.servicePath = './servicePath';
_.unset(module, 'serverless.config.serverless.processedInput.options.path');
module.prepareLocalInvoke();
expect(module.originalServicePath).toEqual('./servicePath');
});
});