1
1
const prompt = require ( "../../packages/webpack-cli/lib/utils/prompt" ) ;
2
+ const { resolve } = require ( "path" ) ;
3
+ // eslint-disable-next-line node/no-unpublished-require
4
+ const execa = require ( "execa" ) ;
2
5
const { Writable } = require ( "stream" ) ;
3
6
4
7
describe ( "prompt" , ( ) => {
@@ -32,9 +35,10 @@ describe("prompt", () => {
32
35
expect ( resultFail ) . toBe ( false ) ;
33
36
} ) ;
34
37
35
- it ( 'should work with "yes" && " y" response' , async ( ) => {
38
+ it ( 'should work with "yes", "YES"," and y" response' , async ( ) => {
36
39
const myWritable1 = new MyWritable ( "yes\r" ) ;
37
40
const myWritable2 = new MyWritable ( "y\r" ) ;
41
+ const myWritable3 = new MyWritable ( "YES\r" ) ;
38
42
39
43
const resultSuccess1 = await prompt ( {
40
44
message : "message" ,
@@ -48,8 +52,15 @@ describe("prompt", () => {
48
52
stream : myWritable2 ,
49
53
} ) ;
50
54
55
+ const resultSuccess3 = await prompt ( {
56
+ message : "message" ,
57
+ defaultResponse : "no" ,
58
+ stream : myWritable3 ,
59
+ } ) ;
60
+
51
61
expect ( resultSuccess1 ) . toBe ( true ) ;
52
62
expect ( resultSuccess2 ) . toBe ( true ) ;
63
+ expect ( resultSuccess3 ) . toBe ( true ) ;
53
64
} ) ;
54
65
55
66
it ( "should work with unknown response" , async ( ) => {
@@ -63,4 +74,19 @@ describe("prompt", () => {
63
74
64
75
expect ( result ) . toBe ( false ) ;
65
76
} ) ;
77
+
78
+ it ( "should respond to SIGINT" , async ( ) => {
79
+ const test = resolve ( __dirname , "./helpers/runAndKillPrompt.js" ) ;
80
+
81
+ const { exitCode, stderr, stdout } = await execa ( "node" , [ test ] , {
82
+ cwd : resolve ( __dirname ) ,
83
+ reject : false ,
84
+ maxBuffer : Infinity ,
85
+ killSignal : "SIGINT" ,
86
+ } ) ;
87
+
88
+ expect ( exitCode ) . toBe ( 0 ) ;
89
+ expect ( stderr ) . toContain ( "[webpack-cli] Operation canceled." ) ;
90
+ expect ( stdout ) . toContain ( "Would you like to install package 'test'? (Yes/No):" ) ;
91
+ } ) ;
66
92
} ) ;
0 commit comments