@@ -51,9 +51,45 @@ test('should use Arborist and run-script', (t) => {
5151 'prepare' ,
5252 'postprepare' ,
5353 ]
54+
55+ // set to true when timer starts, false when it ends
56+ // when the test is done, we assert that all timers ended
57+ const timers = { }
58+ const onTime = msg => {
59+ if ( timers [ msg ] )
60+ throw new Error ( `saw duplicate timer: ${ msg } ` )
61+ timers [ msg ] = true
62+ }
63+ const onTimeEnd = msg => {
64+ if ( ! timers [ msg ] )
65+ throw new Error ( `ended timer that was not started: ${ msg } ` )
66+ timers [ msg ] = false
67+ }
68+ process . on ( 'time' , onTime )
69+ process . on ( 'timeEnd' , onTimeEnd )
70+ t . teardown ( ( ) => {
71+ process . removeListener ( 'time' , onTime )
72+ process . removeListener ( 'timeEnd' , onTimeEnd )
73+ } )
74+
75+ const path = t . testdir ( {
76+ node_modules : {
77+ foo : {
78+ 'package.json' : JSON . stringify ( {
79+ name : 'foo' ,
80+ version : '1.2.3' ,
81+ } ) ,
82+ } ,
83+ '.dotdir' : { } ,
84+ '.dotfile' : 'a file with a dot' ,
85+ } ,
86+ } )
87+ const expectRimrafs = 3
88+ let actualRimrafs = 0
89+
5490 const ci = requireInject ( '../../lib/ci.js' , {
5591 '../../lib/npm.js' : {
56- prefix : 'foo' ,
92+ prefix : path ,
5793 flatOptions : {
5894 global : false ,
5995 } ,
@@ -72,13 +108,11 @@ test('should use Arborist and run-script', (t) => {
72108 t . ok ( true , 'reify is called' )
73109 }
74110 } ,
75- util : {
76- inherits : ( ) => { } ,
77- promisify : ( fn ) => fn ,
78- } ,
79- rimraf : ( path ) => {
111+ rimraf : ( path , ...args ) => {
112+ actualRimrafs ++
80113 t . ok ( path , 'rimraf called with path' )
81- return Promise . resolve ( true )
114+ // callback is always last arg
115+ args . pop ( ) ( )
82116 } ,
83117 '../../lib/utils/reify-output.js' : function ( arb ) {
84118 t . ok ( arb , 'gets arborist tree' )
@@ -87,6 +121,10 @@ test('should use Arborist and run-script', (t) => {
87121 ci ( null , er => {
88122 if ( er )
89123 throw er
124+ for ( const [ msg , result ] of Object . entries ( timers ) )
125+ t . notOk ( result , `properly resolved ${ msg } timer` )
126+ t . match ( timers , { 'npm-ci:rm' : false } , 'saw the rimraf timer' )
127+ t . equal ( actualRimrafs , expectRimrafs , 'removed the right number of things' )
90128 t . strictSame ( scripts , [ ] , 'called all scripts' )
91129 t . end ( )
92130 } )
0 commit comments