@@ -86,17 +86,22 @@ t.afterEach(() => {
8686 WRITE_ERROR = null
8787} )
8888
89+ const runUpdateNotifier = async npm => {
90+ await updateNotifier ( npm )
91+ return npm . updateNotification
92+ }
93+
8994t . test ( 'situations in which we do not notify' , t => {
9095 t . test ( 'nothing to do if notifier disabled' , async t => {
91- t . equal ( await updateNotifier ( {
96+ t . equal ( await runUpdateNotifier ( {
9297 ...npm ,
9398 config : { get : ( k ) => k !== 'update-notifier' } ,
9499 } ) , null )
95100 t . strictSame ( MANIFEST_REQUEST , [ ] , 'no requests for manifests' )
96101 } )
97102
98103 t . test ( 'do not suggest update if already updating' , async t => {
99- t . equal ( await updateNotifier ( {
104+ t . equal ( await runUpdateNotifier ( {
100105 ...npm ,
101106 flatOptions : { ...flatOptions , global : true } ,
102107 command : 'install' ,
@@ -106,7 +111,7 @@ t.test('situations in which we do not notify', t => {
106111 } )
107112
108113 t . test ( 'do not suggest update if already updating with spec' , async t => {
109- t . equal ( await updateNotifier ( {
114+ t . equal ( await runUpdateNotifier ( {
110115 ...npm ,
111116 flatOptions : { ...flatOptions , global : true } ,
112117 command : 'install' ,
@@ -116,31 +121,31 @@ t.test('situations in which we do not notify', t => {
116121 } )
117122
118123 t . test ( 'do not update if same as latest' , async t => {
119- t . equal ( await updateNotifier ( npm ) , null )
124+ t . equal ( await runUpdateNotifier ( npm ) , null )
120125 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' ] , 'requested latest version' )
121126 } )
122127 t . test ( 'check if stat errors (here for coverage)' , async t => {
123128 STAT_ERROR = new Error ( 'blorg' )
124- t . equal ( await updateNotifier ( npm ) , null )
129+ t . equal ( await runUpdateNotifier ( npm ) , null )
125130 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' ] , 'requested latest version' )
126131 } )
127132 t . test ( 'ok if write errors (here for coverage)' , async t => {
128133 WRITE_ERROR = new Error ( 'grolb' )
129- t . equal ( await updateNotifier ( npm ) , null )
134+ t . equal ( await runUpdateNotifier ( npm ) , null )
130135 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' ] , 'requested latest version' )
131136 } )
132137 t . test ( 'ignore pacote failures (here for coverage)' , async t => {
133138 PACOTE_ERROR = new Error ( 'pah-KO-tchay' )
134- t . equal ( await updateNotifier ( npm ) , null )
139+ t . equal ( await runUpdateNotifier ( npm ) , null )
135140 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' ] , 'requested latest version' )
136141 } )
137142 t . test ( 'do not update if newer than latest, but same as next' , async t => {
138- t . equal ( await updateNotifier ( { ...npm , version : NEXT_VERSION } ) , null )
143+ t . equal ( await runUpdateNotifier ( { ...npm , version : NEXT_VERSION } ) , null )
139144 const reqs = [ 'npm@latest' , `npm@^${ NEXT_VERSION } ` ]
140145 t . strictSame ( MANIFEST_REQUEST , reqs , 'requested latest and next versions' )
141146 } )
142147 t . test ( 'do not update if on the latest beta' , async t => {
143- t . equal ( await updateNotifier ( { ...npm , version : CURRENT_BETA } ) , null )
148+ t . equal ( await runUpdateNotifier ( { ...npm , version : CURRENT_BETA } ) , null )
144149 const reqs = [ `npm@^${ CURRENT_BETA } ` ]
145150 t . strictSame ( MANIFEST_REQUEST , reqs , 'requested latest and next versions' )
146151 } )
@@ -150,21 +155,21 @@ t.test('situations in which we do not notify', t => {
150155 ciMock = null
151156 } )
152157 ciMock = 'something'
153- t . equal ( await updateNotifier ( npm ) , null )
158+ t . equal ( await runUpdateNotifier ( npm ) , null )
154159 t . strictSame ( MANIFEST_REQUEST , [ ] , 'no requests for manifests' )
155160 } )
156161
157162 t . test ( 'only check weekly for GA releases' , async t => {
158163 // One week (plus five minutes to account for test environment fuzziness)
159164 STAT_MTIME = Date . now ( ) - ( 1000 * 60 * 60 * 24 * 7 ) + ( 1000 * 60 * 5 )
160- t . equal ( await updateNotifier ( npm ) , null )
165+ t . equal ( await runUpdateNotifier ( npm ) , null )
161166 t . strictSame ( MANIFEST_REQUEST , [ ] , 'no requests for manifests' )
162167 } )
163168
164169 t . test ( 'only check daily for betas' , async t => {
165170 // One day (plus five minutes to account for test environment fuzziness)
166171 STAT_MTIME = Date . now ( ) - ( 1000 * 60 * 60 * 24 ) + ( 1000 * 60 * 5 )
167- t . equal ( await updateNotifier ( { ...npm , version : HAVE_BETA } ) , null )
172+ t . equal ( await runUpdateNotifier ( { ...npm , version : HAVE_BETA } ) , null )
168173 t . strictSame ( MANIFEST_REQUEST , [ ] , 'no requests for manifests' )
169174 } )
170175
@@ -174,43 +179,43 @@ t.test('situations in which we do not notify', t => {
174179t . test ( 'notification situations' , t => {
175180 t . test ( 'new beta available' , async t => {
176181 const version = HAVE_BETA
177- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
178- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
182+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
183+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
179184 t . strictSame ( MANIFEST_REQUEST , [ `npm@^${ version } ` , `npm@^${ version } ` ] )
180185 } )
181186
182187 t . test ( 'patch to next version' , async t => {
183188 const version = NEXT_PATCH
184- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
185- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
189+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
190+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
186191 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' , `npm@^${ version } ` , 'npm@latest' , `npm@^${ version } ` ] )
187192 } )
188193
189194 t . test ( 'minor to next version' , async t => {
190195 const version = NEXT_MINOR
191- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
192- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
196+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
197+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
193198 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' , `npm@^${ version } ` , 'npm@latest' , `npm@^${ version } ` ] )
194199 } )
195200
196201 t . test ( 'patch to current' , async t => {
197202 const version = CURRENT_PATCH
198- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
199- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
203+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
204+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
200205 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' , 'npm@latest' ] )
201206 } )
202207
203208 t . test ( 'minor to current' , async t => {
204209 const version = CURRENT_MINOR
205- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
206- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
210+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
211+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
207212 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' , 'npm@latest' ] )
208213 } )
209214
210215 t . test ( 'major to current' , async t => {
211216 const version = CURRENT_MAJOR
212- t . matchSnapshot ( await updateNotifier ( { ...npm , version } ) , 'color' )
213- t . matchSnapshot ( await updateNotifier ( { ...npmNoColor , version } ) , 'no color' )
217+ t . matchSnapshot ( await runUpdateNotifier ( { ...npm , version } ) , 'color' )
218+ t . matchSnapshot ( await runUpdateNotifier ( { ...npmNoColor , version } ) , 'no color' )
214219 t . strictSame ( MANIFEST_REQUEST , [ 'npm@latest' , 'npm@latest' ] )
215220 } )
216221
0 commit comments