File tree 6 files changed +51
-43
lines changed
6 files changed +51
-43
lines changed Original file line number Diff line number Diff line change 1
- const path = require ( ' path' ) ;
2
- const { createCommandInterface } = require ( ' ../../lib' ) ;
1
+ const path = require ( " path" ) ;
2
+ const { createCommandInterface } = require ( " ../../lib" ) ;
3
3
4
- const wait = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
4
+ const wait = ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
5
5
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" ) ;
12
15
// await wait(100);
13
- await commandInterface . type ( ' saurabh\n' ) ;
16
+ await commandInterface . type ( " saurabh\n" ) ;
14
17
const terminal = await commandInterface . getOutput ( ) ;
15
18
console . log ( terminal ) ;
16
19
expect ( 1 ) . toBe ( 1 ) ;
Original file line number Diff line number Diff line change 1
- const path = require ( ' path' ) ;
2
- const { createCommandInterface } = require ( ' ../../lib' ) ;
1
+ const path = require ( " path" ) ;
2
+ const { createCommandInterface } = require ( " ../../lib" ) ;
3
3
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 , ".." ) ,
7
10
} ) ;
8
- await commandInterface . type ( ' 12\n' ) ;
11
+ await commandInterface . type ( " 12\n" ) ;
9
12
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
+ ) ;
11
16
} ) ;
Original file line number Diff line number Diff line change 1
- const path = require ( ' path' ) ;
2
- const { createCommandInterface } = require ( ' ../../lib' ) ;
1
+ const path = require ( " path" ) ;
2
+ const { createCommandInterface } = require ( " ../../lib" ) ;
3
3
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 , ".." ) ,
7
7
} ) ;
8
- await commandInterface . type ( ' Saurabh\n' ) ;
9
- await commandInterface . type ( ' 22\n' ) ;
8
+ await commandInterface . type ( " Saurabh\n" ) ;
9
+ await commandInterface . type ( " 22\n" ) ;
10
10
const terminal = await commandInterface . getOutput ( ) ;
11
11
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!
14
14
} ) ;
Original file line number Diff line number Diff line change 1
- const prompts = require ( ' prompts' ) ;
1
+ const prompts = require ( " prompts" ) ;
2
2
3
3
( async ( ) => {
4
4
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 ) ,
9
9
} ) ;
10
10
11
11
console . log ( response1 ) ; // => { value: 24 }
12
12
13
13
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?" ,
17
17
} ) ;
18
18
19
19
console . log ( response2 ) ;
20
- } ) ( ) ;
20
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
- const prompts = require ( ' prompts' ) ;
1
+ const prompts = require ( " prompts" ) ;
2
2
3
3
( async ( ) => {
4
4
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 ) ,
9
9
} ) ;
10
10
11
11
console . log ( response ) ; // => { value: 24 }
12
- } ) ( ) ;
12
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
- const readline = require ( ' readline' ) . createInterface ( {
1
+ const readline = require ( " readline" ) . createInterface ( {
2
2
input : process . stdin ,
3
- output : process . stdout
3
+ output : process . stdout ,
4
4
} ) ;
5
5
6
6
readline . question ( `What's your name?` , ( name ) => {
You can’t perform that action at this time.
0 commit comments