-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
create-from-local-template.test.js
63 lines (53 loc) · 2.13 KB
/
create-from-local-template.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
'use strict';
const path = require('path');
const chai = require('chai');
const fsp = require('fs').promises;
const { load: yamlParse } = require('js-yaml');
const createFromLocalTemplate = require('../../../../lib/utils/create-from-local-template');
const { getTmpDirPath } = require('../../../utils/fs');
const templatesPath = path.resolve(__dirname, '../../../../lib/plugins/create/templates');
chai.use(require('chai-as-promised'));
const expect = chai.expect;
describe('test/unit/lib/utils/create-from-local-template.test.js', () => {
describe('Without `projectName` provided', () => {
it('should create from template referenced locally', async () => {
const tmpDirPath = path.join(getTmpDirPath(), 'some-service');
await createFromLocalTemplate({
templatePath: path.join(templatesPath, 'aws-nodejs'),
projectDir: tmpDirPath,
});
const stats = await fsp.lstat(path.join(tmpDirPath, 'serverless.yml'));
expect(stats.isFile()).to.be.true;
});
});
describe('When `templatePath` does not exist', () => {
it('should result in an error', async () => {
const tmpDirPath = path.join(getTmpDirPath(), 'some-service');
await expect(
createFromLocalTemplate({
templatePath: path.join(templatesPath, 'nonexistent'),
projectDir: tmpDirPath,
})
).to.eventually.be.rejected.and.have.property('code', 'INVALID_TEMPLATE_PATH');
});
});
describe('With `projectName` provided', () => {
let tmpDirPath;
before(async () => {
tmpDirPath = path.join(getTmpDirPath(), 'some-service');
await createFromLocalTemplate({
templatePath: path.join(templatesPath, 'fn-nodejs'),
projectDir: tmpDirPath,
projectName: 'testproj',
});
});
it('should set service name in serverless.yml', async () =>
expect(
yamlParse(await fsp.readFile(path.join(tmpDirPath, 'serverless.yml'))).service
).to.equal('testproj'));
it('should set name in package.json', async () =>
expect(JSON.parse(await fsp.readFile(path.join(tmpDirPath, 'package.json'))).name).to.equal(
'testproj'
));
});
});