-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathcleanupServerlessDir.test.js
77 lines (62 loc) · 2.5 KB
/
cleanupServerlessDir.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
'use strict';
const path = require('path');
const sinon = require('sinon');
const fse = require('fs-extra');
const GoogleProvider = require('../../provider/googleProvider');
const GooglePackage = require('../googlePackage');
const Serverless = require('../../test/serverless');
describe('CleanupServerlessDir', () => {
let serverless;
let googlePackage;
let pathExistsSyncStub;
let removeSyncStub;
beforeEach(() => {
serverless = new Serverless();
serverless.service.service = 'my-service';
serverless.config = {
servicePath: false,
};
serverless.setProvider('google', new GoogleProvider(serverless));
const options = {
stage: 'dev',
region: 'us-central1',
};
googlePackage = new GooglePackage(serverless, options);
pathExistsSyncStub = sinon.stub(fse, 'pathExistsSync');
removeSyncStub = sinon.stub(fse, 'removeSync').returns();
});
afterEach(() => {
fse.pathExistsSync.restore();
fse.removeSync.restore();
});
describe('#cleanupServerlessDir()', () => {
it('should resolve if no servicePath is given', () => {
googlePackage.serverless.config.servicePath = false;
pathExistsSyncStub.returns();
return googlePackage.cleanupServerlessDir().then(() => {
expect(pathExistsSyncStub.calledOnce).toEqual(false);
expect(removeSyncStub.calledOnce).toEqual(false);
});
});
it('should remove the .serverless directory if it exists', () => {
const serviceName = googlePackage.serverless.service.service;
googlePackage.serverless.config.servicePath = serviceName;
const serverlessDirPath = path.join(serviceName, '.serverless');
pathExistsSyncStub.returns(true);
return googlePackage.cleanupServerlessDir().then(() => {
expect(pathExistsSyncStub.calledWithExactly(serverlessDirPath)).toEqual(true);
expect(removeSyncStub.calledWithExactly(serverlessDirPath)).toEqual(true);
});
});
it('should not remove the .serverless directory if does not exist', () => {
const serviceName = googlePackage.serverless.service.service;
googlePackage.serverless.config.servicePath = serviceName;
const serverlessDirPath = path.join(serviceName, '.serverless');
pathExistsSyncStub.returns(false);
return googlePackage.cleanupServerlessDir().then(() => {
expect(pathExistsSyncStub.calledWithExactly(serverlessDirPath)).toEqual(true);
expect(removeSyncStub.calledWithExactly(serverlessDirPath)).toEqual(false);
});
});
});
});