Skip to content

Commit 2f1fae7

Browse files
test: migrate to cli-prompts-test
1 parent f824973 commit 2f1fae7

File tree

4 files changed

+165
-30
lines changed

4 files changed

+165
-30
lines changed

__e2e__/commands/add.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('mevn add', () => {
112112
});
113113

114114
it('shows a warning if no args were passed in for server directory', async () => {
115-
const stdout = await runPromptWithAnswers(
115+
const { stdout } = await runPromptWithAnswers(
116116
['add'],
117117
[`${DOWN}${ENTER}`], // opts for server directory
118118
genPath,
@@ -134,7 +134,7 @@ describe('mevn add', () => {
134134
);
135135

136136
// Invoke the add command
137-
const stdout = await runPromptWithAnswers(
137+
const { stdout } = await runPromptWithAnswers(
138138
['add'],
139139
[ENTER], // opts for client directory
140140
genPath,

jest/helpers.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import 'babel-polyfill';
4-
import concat from 'concat-stream';
4+
import runTest from 'cli-prompts-test';
55
import execa from 'execa';
66
import fs from 'fs';
77
import path from 'path';
@@ -13,31 +13,9 @@ export const run = (args, options = {}) => execa.sync(CLI_PATH, args, options);
1313

1414
// Test cases that require simulating user input
1515
export const runPromptWithAnswers = (args, answers, testPath) => {
16-
args = [CLI_PATH].concat(args);
17-
18-
const process = execa('node', args, { cwd: testPath });
19-
process.stdin.setEncoding('utf-8');
20-
21-
const writeToStdin = (answers) => {
22-
if (answers.length > 0) {
23-
setTimeout(() => {
24-
process.stdin.write(answers[0]);
25-
writeToStdin(answers.slice(1));
26-
}, 3000);
27-
} else {
28-
process.stdin.end();
29-
}
30-
};
31-
32-
// Simulate user input
33-
writeToStdin(answers);
34-
35-
return new Promise((resolve) => {
36-
process.stdout.pipe(
37-
concat((result) => {
38-
resolve(result.toString());
39-
}),
40-
);
16+
return runTest([CLI_PATH].concat(args), answers, {
17+
testPath,
18+
timeout: 2000,
4119
});
4220
};
4321

package-lock.json

Lines changed: 158 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"@commitlint/config-conventional": "^8.3.4",
7777
"babel-eslint": "^10.1.0",
7878
"babel-jest": "^24.9.0",
79+
"cli-prompts-test": "^0.1.1",
7980
"del": "^4.1.1",
8081
"eslint": "^5.16.0",
8182
"eslint-config-prettier": "4.1.0",

0 commit comments

Comments
 (0)