forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetServerlessConfigFile.test.js
More file actions
76 lines (61 loc) · 2.7 KB
/
getServerlessConfigFile.test.js
File metadata and controls
76 lines (61 loc) · 2.7 KB
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
'use strict';
const path = require('path');
const expect = require('chai').expect;
const testUtils = require('../../tests/utils');
const writeFileSync = require('./fs/writeFileSync');
const getServerlessConfigFile = require('./getServerlessConfigFile');
describe('#getServerlessConfigFile()', () => {
let tmpDirPath;
beforeEach(() => {
tmpDirPath = testUtils.getTmpDirPath();
});
it('should return an empty string if no serverless file is found', () => {
const randomFilePath = path.join(tmpDirPath, 'not-a-serverless-file');
writeFileSync(randomFilePath, 'some content');
return expect(getServerlessConfigFile(tmpDirPath)).to.be.fulfilled.then((result) => {
expect(result).to.equal('');
});
});
it('should return the file content if a serverless.yml file is found', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.yml');
writeFileSync(serverlessFilePath, 'service: my-yml-service');
return expect(getServerlessConfigFile(tmpDirPath)).to.be.fulfilled.then((result) => {
expect(result).to.deep.equal({ service: 'my-yml-service' });
});
});
it('should return the file content if a serverless.yaml file is found', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.yaml');
writeFileSync(serverlessFilePath, 'service: my-yaml-service');
return expect(getServerlessConfigFile(tmpDirPath)).to.be.fulfilled.then((result) => {
expect(result).to.deep.equal({ service: 'my-yaml-service' });
});
});
it('should return the file content if a serverless.json file is found', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.json');
writeFileSync(serverlessFilePath, '{ "service": "my-json-service" }');
return expect(getServerlessConfigFile(tmpDirPath)).to.be.fulfilled.then((result) => {
expect(result).to.deep.equal({ service: 'my-json-service' });
});
});
it('should return the file content if a serverless.js file found', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.js');
writeFileSync(
serverlessFilePath,
'module.exports = {"service": "my-json-service"};'
);
return expect(getServerlessConfigFile(tmpDirPath)).to.be.fulfilled.then(
(result) => {
expect(result).to.deep.equal({ service: 'my-json-service' });
}
);
});
it('should throw an error, if serverless.js export not a plain object', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.js');
writeFileSync(
serverlessFilePath,
'module.exports = function config() {};'
);
return expect(getServerlessConfigFile(tmpDirPath))
.to.be.rejectedWith('serverless.js must export plain object');
});
});