-
Notifications
You must be signed in to change notification settings - Fork 415
/
Copy pathprepareStepOfflineInvoke.test.js
121 lines (104 loc) · 3.71 KB
/
prepareStepOfflineInvoke.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const _ = require('lodash');
const BbPromise = require('bluebird');
const Serverless = require('serverless');
const baseModule = require('../lib/prepareStepOfflineInvoke');
describe('prepareStepOfflineInvoke', () => {
let serverless;
let module;
beforeEach(() => {
serverless = new Serverless({ commands: ['print'], options: {}, serviceDir: null });
serverless.cli = {
log: jest.fn()
};
serverless.pluginManager.spawn = jest.fn();
module = _.assign(
{
serverless,
options: {}
},
baseModule
);
});
it('should set service packaging explicitly', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = 'myPath';
module.webpackOutputPath = '.';
module.serverless.service.package = {};
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(module.serverless.service.package).toHaveProperty('individually', false);
return null;
});
});
it('should switch to service packaging', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = 'myPath';
module.webpackOutputPath = '.';
module.serverless.service.package = {
individually: true
};
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(module.serverless.service.package).toHaveProperty('individually', false);
return null;
});
});
it('should spawn webpack:validate', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = 'myPath';
module.webpackOutputPath = '.';
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(serverless.pluginManager.spawn).toHaveBeenCalledTimes(1);
expect(serverless.pluginManager.spawn).toHaveBeenCalledWith('webpack:validate');
return null;
});
});
it('should reject if spawn rejects', () => {
serverless.pluginManager.spawn.mockReturnValue(BbPromise.reject(new Error('spawn failed')));
serverless.config.servicePath = 'myPath';
module.webpackOutputPath = '.';
return expect(module.prepareStepOfflineInvoke()).rejects.toThrow('spawn failed');
});
it('should set location if not given by user', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = '.';
module.webpackOutputPath = '.';
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(serverless.service).toHaveProperty('custom.stepFunctionsOffline.location', 'service');
return null;
});
});
it('should keep location if set in service config', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = '.';
module.webpackOutputPath = '.';
_.set(module.serverless, 'service.custom.stepFunctionsOffline.location', 'myLocation');
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(serverless.service).toHaveProperty('custom.stepFunctionsOffline.location', 'myLocation');
return null;
});
});
it('should keep location if set in options', () => {
serverless.pluginManager.spawn.mockResolvedValue();
serverless.config.servicePath = '.';
module.webpackOutputPath = '.';
module.options = {
location: 'myLocation'
};
return expect(module.prepareStepOfflineInvoke())
.resolves.toBe(null)
.then(() => {
expect(serverless.service).not.toHaveProperty('custom.stepFunctionsOffline.location');
return null;
});
});
});