Skip to content

Commit 1897096

Browse files
author
Walker Leite
committed
fix(test): add extended tests
1 parent f10fb19 commit 1897096

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

test.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
const {spawn} = require('child_process');
22

3+
const initQuestions = [
4+
{search: /^\?.+/, response: "\n"},
5+
];
6+
7+
const initNoExtQuestions = [
8+
{ search: /^\? Add basic Login and Admin.+/, response: "No\n" },
9+
{ search: /^\?.+/, response: "\n" },
10+
];
11+
312
const commands = [
413
{cmd: 'rm', args: ['-r', 'test-project'], ignoreErrors: true},
5-
{cmd: './node_modules/.bin/vue', args: ['init', '.', 'test-project'], yes: true},
14+
{cmd: './node_modules/.bin/vue', args: ['init', '.', 'test-project'], responses: initNoExtQuestions},
615
{cmd: 'npm', args: ['install'], cwd: 'test-project'},
716
{cmd: 'npm', args: ['run', 'lint'], cwd: 'test-project'},
817
{cmd: 'npm', args: ['run', 'test:server'], cwd: 'test-project'},
918
{cmd: 'npm', args: ['run', 'test:client'], cwd: 'test-project'},
1019
{cmd: 'npm', args: ['run', 'build'], cwd: 'test-project'},
20+
{cmd: 'rm', args: ['-r', 'test-project'], ignoreErrors: true},
21+
{ cmd: './node_modules/.bin/vue', args: ['init', '.', 'test-project'], responses: initNoExtQuestions},
22+
{ cmd: 'npm', args: ['install'], cwd: 'test-project' },
23+
{ cmd: 'npm', args: ['run', 'lint'], cwd: 'test-project' },
24+
{ cmd: 'npm', args: ['run', 'test:server'], cwd: 'test-project' },
25+
{ cmd: 'npm', args: ['run', 'test:client'], cwd: 'test-project' },
26+
{ cmd: 'npm', args: ['run', 'build'], cwd: 'test-project' },
1127
];
1228

1329
function executeCommand(command, index) {
1430
return new Promise((resolve, reject) => {
1531
let cp = spawn(command.cmd, command.args, {cwd: command.cwd});
1632
process.on('exit', cp.kill);
17-
1833
cp.stdout.setEncoding('utf-8');
1934
cp.stdin.setEncoding('utf-8');
35+
cp.stderr.setEncoding('utf-8');
2036

2137
// Ignore pipe errors
2238
cp.stdin.on('error', () => {});
@@ -26,18 +42,25 @@ function executeCommand(command, index) {
2642
cp.stderr.pipe(process.stderr);
2743

2844
let rejected = false;
29-
if(command.yes) {
30-
cp.stdout.on('data', function() {
31-
if (!rejected) cp.stdin.write("\n");
32-
});
33-
}
45+
if (!rejected && command.responses) {
46+
const registerResponse = q => {
47+
cp.stdout.on('data', output => {
48+
if (q.search.test(output)) {
49+
// console.log('sending', q);
50+
cp.stdin.write(q.response);
51+
}
52+
});
53+
}
54+
55+
command.responses.forEach(registerResponse);
56+
}
3457
cp.once('error', code => {
3558
if (!rejected) {
3659
reject(code);
3760
rejected = true;
3861
}
3962
});
40-
63+
4164
cp.once('exit', code => {
4265
if (code) {
4366
reject(code);

0 commit comments

Comments
 (0)