forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.test.js
81 lines (72 loc) · 2.79 KB
/
create.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
'use strict';
const path = require('path');
const fsp = require('fs').promises;
const fse = require('fs-extra');
const spawn = require('child-process-ext/spawn');
const { getTmpDirPath } = require('../utils/fs');
const { expect } = require('chai');
const serverlessExec = require('../serverless-binary');
describe('test/integration/create.test.js', function () {
this.timeout(1000 * 60 * 2);
it('should generate scaffolding for "aws-nodejs" template in provided path and rename service', async () => {
const tmpDir = getTmpDirPath();
await spawn(serverlessExec, [
'create',
'--template',
'aws-nodejs',
'--path',
tmpDir,
'--name',
'new-service-name',
]);
const dirContent = await fsp.readdir(tmpDir);
expect(dirContent).to.include('handler.js');
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('.gitignore');
const serverlessYmlfileContent = (
await fsp.readFile(path.join(tmpDir, 'serverless.yml'))
).toString();
expect(serverlessYmlfileContent).to.include('service: new-service-name');
});
it('should generate scaffolding for "aws-nodejs" template in current directory', async () => {
const tmpDir = getTmpDirPath();
await fse.ensureDir(tmpDir);
await spawn(serverlessExec, ['create', '--template', 'aws-nodejs'], {
cwd: tmpDir,
});
const dirContent = await fsp.readdir(tmpDir);
expect(dirContent).to.include('handler.js');
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('.gitignore');
const serverlessYmlfileContent = (
await fsp.readFile(path.join(tmpDir, 'serverless.yml'))
).toString();
// We are checking that it includes basename of dir as it will be included in service name
expect(serverlessYmlfileContent).to.include(path.basename(tmpDir));
});
it('should generate scaffolding for "plugin" template', async () => {
const tmpDir = getTmpDirPath();
await fse.ensureDir(tmpDir);
await spawn(serverlessExec, ['create', '--template', 'plugin'], {
cwd: tmpDir,
});
const dirContent = await fsp.readdir(tmpDir);
expect(dirContent).to.include('index.js');
expect(dirContent).to.include('README.md');
expect(dirContent).to.include('package.json');
});
it('should error out when trying to create project in current working dir and the project files are already present in it', async () => {
const tmpDir = getTmpDirPath();
await fse.ensureDir(tmpDir);
await fsp.writeFile(path.join(tmpDir, 'handler.js'), '');
let err;
try {
await spawn(serverlessExec, ['create', '--template', 'aws-nodejs'], {
cwd: tmpDir,
});
} catch (e) {
err = e;
}
expect(err.stdoutBuffer.toString()).to.contain('Move it and try again');
});
});