Skip to content

Commit 4acf60a

Browse files
committed
fix tests for windows
1 parent f09deff commit 4acf60a

File tree

6 files changed

+51
-43
lines changed

6 files changed

+51
-43
lines changed

cli-examples/__tests__/multiple-prompts.test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
const path = require('path');
2-
const { createCommandInterface } = require('../../lib');
1+
const path = require("path");
2+
const { createCommandInterface } = require("../../lib");
33

4-
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
4+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
55

6-
test('should pass', async () => {
7-
const commandInterface = createCommandInterface('node ./multiple-prompts.js', {
8-
cwd: path.join(__dirname, '..'),
9-
logData: true,
10-
});
11-
await commandInterface.type('19\n');
6+
test("should pass", async () => {
7+
const commandInterface = createCommandInterface(
8+
"node ./multiple-prompts.js",
9+
{
10+
cwd: path.join(__dirname, ".."),
11+
logData: true,
12+
}
13+
);
14+
await commandInterface.type("19\n");
1215
// await wait(100);
13-
await commandInterface.type('saurabh\n');
16+
await commandInterface.type("saurabh\n");
1417
const terminal = await commandInterface.getOutput();
1518
console.log(terminal);
1619
expect(1).toBe(1);
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
const path = require('path');
2-
const { createCommandInterface } = require('../../lib');
1+
const path = require("path");
2+
const { createCommandInterface } = require("../../lib");
33

4-
test('should block 12 year old', async () => {
5-
const commandInterface = createCommandInterface('node ./prompts.js', {
6-
cwd: path.join(__dirname, '..'),
4+
// Windows is just weird.
5+
const FORWARD_ARROW = process.platform === "win32" ? "»" : "›";
6+
7+
test("should block 12 year old", async () => {
8+
const commandInterface = createCommandInterface("node ./prompts.js", {
9+
cwd: path.join(__dirname, ".."),
710
});
8-
await commandInterface.type('12\n');
11+
await commandInterface.type("12\n");
912
const terminal = await commandInterface.getOutput();
10-
expect(terminal.stringOutput).toBe('? How old are you? › 12\n› Nightclub is 18+ only');
13+
expect(terminal.stringOutput).toBe(
14+
`? How old are you? ${FORWARD_ARROW} 12\n${FORWARD_ARROW} Nightclub is 18+ only`
15+
);
1116
});
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
const path = require('path');
2-
const { createCommandInterface } = require('../../lib');
1+
const path = require("path");
2+
const { createCommandInterface } = require("../../lib");
33

4-
test('should pass', async () => {
5-
const commandInterface = createCommandInterface('node ./simple-print.js', {
6-
cwd: path.join(__dirname, '..'),
4+
test("should pass", async () => {
5+
const commandInterface = createCommandInterface("node ./simple-print.js", {
6+
cwd: path.join(__dirname, ".."),
77
});
8-
await commandInterface.type('Saurabh\n');
9-
await commandInterface.type('22\n');
8+
await commandInterface.type("Saurabh\n");
9+
await commandInterface.type("22\n");
1010
const terminal = await commandInterface.getOutput();
1111

12-
expect(terminal.textAfter("What's your name?")).toBe('Hi, Saurabh!'); // Hi, Saurabh!
13-
expect(terminal.textAfter("What's your age?")).toBe('So you are 22!'); // So you are 22!
12+
expect(terminal.textAfter("What's your name?")).toBe("Hi, Saurabh!"); // Hi, Saurabh!
13+
expect(terminal.textAfter("What's your age?")).toBe("So you are 22!"); // So you are 22!
1414
});

cli-examples/multiple-prompts.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const prompts = require('prompts');
1+
const prompts = require("prompts");
22

33
(async () => {
44
const response1 = await prompts({
5-
type: 'number',
6-
name: 'value',
7-
message: 'How old are you?',
8-
validate: value => value < 18 ? `Nightclub is 18+ only` : true
5+
type: "number",
6+
name: "value",
7+
message: "How old are you?",
8+
validate: (value) => (value < 18 ? `Nightclub is 18+ only` : true),
99
});
1010

1111
console.log(response1); // => { value: 24 }
1212

1313
const response2 = await prompts({
14-
type: 'text',
15-
name: 'value',
16-
message: 'What is your name?',
14+
type: "text",
15+
name: "value",
16+
message: "What is your name?",
1717
});
1818

1919
console.log(response2);
20-
})();
20+
})();

cli-examples/prompts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const prompts = require('prompts');
1+
const prompts = require("prompts");
22

33
(async () => {
44
const response = await prompts({
5-
type: 'number',
6-
name: 'value',
7-
message: 'How old are you?',
8-
validate: value => value < 18 ? `Nightclub is 18+ only` : true
5+
type: "number",
6+
name: "value",
7+
message: "How old are you?",
8+
validate: (value) => (value < 18 ? `Nightclub is 18+ only` : true),
99
});
1010

1111
console.log(response); // => { value: 24 }
12-
})();
12+
})();

cli-examples/simple-print.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const readline = require('readline').createInterface({
1+
const readline = require("readline").createInterface({
22
input: process.stdin,
3-
output: process.stdout
3+
output: process.stdout,
44
});
55

66
readline.question(`What's your name?`, (name) => {

0 commit comments

Comments
 (0)