@@ -29,24 +29,33 @@ for (const npmDir of ['npm8', 'npm10']) {
29
29
const entryPath = path . join ( constants . rootBinPath , 'cli.js' )
30
30
31
31
it ( 'should bail on new typosquat' , async ( ) => {
32
- await assert . rejects (
32
+ await assert . doesNotReject (
33
33
( ) =>
34
- spawn (
35
- // Lazily access constants.execPath.
36
- constants . execPath ,
37
- [ entryPath , NPM , 'install' , 'bowserify' ] ,
38
- {
39
- cwd : path . join ( npmFixturesPath , 'lacking-typosquat' ) ,
40
- encoding : 'utf8' ,
41
- env : {
42
- // Make sure we don't borrow TTY from parent.
43
- SOCKET_SECURITY_TTY_IPC : undefined ,
44
- PATH : `${ npmBinPath } :${ process . env . PATH } `
45
- } ,
46
- signal : abortSignal
47
- }
48
- ) ,
49
- e => e ?. stderr . includes ( 'Unable to prompt' )
34
+ new Promise ( ( resolve , reject ) => {
35
+ const promise = spawn (
36
+ // Lazily access constants.execPath.
37
+ constants . execPath ,
38
+ [ entryPath , NPM , 'install' , 'bowserify' ] ,
39
+ {
40
+ cwd : path . join ( npmFixturesPath , 'lacking-typosquat' ) ,
41
+ encoding : 'utf8' ,
42
+ env : {
43
+ PATH : `${ npmBinPath } :${ process . env . PATH } `
44
+ } ,
45
+ signal : abortSignal
46
+ }
47
+ )
48
+ promise . process . stderr . on ( 'data' , buffer => {
49
+ if ( buffer . toString ( ) . includes ( 'Possible typosquat attack' ) ) {
50
+ promise . process . kill ( 'SIGINT' )
51
+ resolve ( )
52
+ }
53
+ } )
54
+ promise . catch ( ( ) => {
55
+ promise . process . kill ( 'SIGINT' )
56
+ reject ( )
57
+ } )
58
+ } )
50
59
)
51
60
} )
52
61
} )
0 commit comments