fix(update-notifier): parallelize check for updates · npm/cli@aafe235 (original) (raw)
`@@ -86,17 +86,22 @@ t.afterEach(() => {
`
86
86
`WRITE_ERROR = null
`
87
87
`})
`
88
88
``
``
89
`+
const runUpdateNotifier = async npm => {
`
``
90
`+
await updateNotifier(npm)
`
``
91
`+
return npm.updateNotification
`
``
92
`+
}
`
``
93
+
89
94
`t.test('situations in which we do not notify', t => {
`
90
95
`t.test('nothing to do if notifier disabled', async t => {
`
91
``
`-
t.equal(await updateNotifier({
`
``
96
`+
t.equal(await runUpdateNotifier({
`
92
97
` ...npm,
`
93
98
`config: { get: (k) => k !== 'update-notifier' },
`
94
99
`}), null)
`
95
100
`t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
`
96
101
`})
`
97
102
``
98
103
`t.test('do not suggest update if already updating', async t => {
`
99
``
`-
t.equal(await updateNotifier({
`
``
104
`+
t.equal(await runUpdateNotifier({
`
100
105
` ...npm,
`
101
106
`flatOptions: { ...flatOptions, global: true },
`
102
107
`command: 'install',
`
`@@ -106,7 +111,7 @@ t.test('situations in which we do not notify', t => {
`
106
111
`})
`
107
112
``
108
113
`t.test('do not suggest update if already updating with spec', async t => {
`
109
``
`-
t.equal(await updateNotifier({
`
``
114
`+
t.equal(await runUpdateNotifier({
`
110
115
` ...npm,
`
111
116
`flatOptions: { ...flatOptions, global: true },
`
112
117
`command: 'install',
`
`@@ -116,31 +121,31 @@ t.test('situations in which we do not notify', t => {
`
116
121
`})
`
117
122
``
118
123
`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)
`
120
125
`t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
`
121
126
`})
`
122
127
`t.test('check if stat errors (here for coverage)', async t => {
`
123
128
`STAT_ERROR = new Error('blorg')
`
124
``
`-
t.equal(await updateNotifier(npm), null)
`
``
129
`+
t.equal(await runUpdateNotifier(npm), null)
`
125
130
`t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
`
126
131
`})
`
127
132
`t.test('ok if write errors (here for coverage)', async t => {
`
128
133
`WRITE_ERROR = new Error('grolb')
`
129
``
`-
t.equal(await updateNotifier(npm), null)
`
``
134
`+
t.equal(await runUpdateNotifier(npm), null)
`
130
135
`t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
`
131
136
`})
`
132
137
`t.test('ignore pacote failures (here for coverage)', async t => {
`
133
138
`PACOTE_ERROR = new Error('pah-KO-tchay')
`
134
``
`-
t.equal(await updateNotifier(npm), null)
`
``
139
`+
t.equal(await runUpdateNotifier(npm), null)
`
135
140
`t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
`
136
141
`})
`
137
142
`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)
`
139
144
`` const reqs = ['npm@latest', npm@^${NEXT_VERSION}]
``
140
145
`t.strictSame(MANIFEST_REQUEST, reqs, 'requested latest and next versions')
`
141
146
`})
`
142
147
`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)
`
144
149
`` const reqs = [npm@^${CURRENT_BETA}]
``
145
150
`t.strictSame(MANIFEST_REQUEST, reqs, 'requested latest and next versions')
`
146
151
`})
`
`@@ -150,21 +155,21 @@ t.test('situations in which we do not notify', t => {
`
150
155
`ciMock = null
`
151
156
`})
`
152
157
`ciMock = 'something'
`
153
``
`-
t.equal(await updateNotifier(npm), null)
`
``
158
`+
t.equal(await runUpdateNotifier(npm), null)
`
154
159
`t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
`
155
160
`})
`
156
161
``
157
162
`t.test('only check weekly for GA releases', async t => {
`
158
163
`// One week (plus five minutes to account for test environment fuzziness)
`
159
164
`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)
`
161
166
`t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
`
162
167
`})
`
163
168
``
164
169
`t.test('only check daily for betas', async t => {
`
165
170
`// One day (plus five minutes to account for test environment fuzziness)
`
166
171
`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)
`
168
173
`t.strictSame(MANIFEST_REQUEST, [], 'no requests for manifests')
`
169
174
`})
`
170
175
``
`@@ -174,43 +179,43 @@ t.test('situations in which we do not notify', t => {
`
174
179
`t.test('notification situations', t => {
`
175
180
`t.test('new beta available', async t => {
`
176
181
`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')
`
179
184
`` t.strictSame(MANIFEST_REQUEST, [npm@^${version}, npm@^${version}])
``
180
185
`})
`
181
186
``
182
187
`t.test('patch to next version', async t => {
`
183
188
`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')
`
186
191
`` t.strictSame(MANIFEST_REQUEST, ['npm@latest', npm@^${version}, 'npm@latest', npm@^${version}])
``
187
192
`})
`
188
193
``
189
194
`t.test('minor to next version', async t => {
`
190
195
`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')
`
193
198
`` t.strictSame(MANIFEST_REQUEST, ['npm@latest', npm@^${version}, 'npm@latest', npm@^${version}])
``
194
199
`})
`
195
200
``
196
201
`t.test('patch to current', async t => {
`
197
202
`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')
`
200
205
`t.strictSame(MANIFEST_REQUEST, ['npm@latest', 'npm@latest'])
`
201
206
`})
`
202
207
``
203
208
`t.test('minor to current', async t => {
`
204
209
`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')
`
207
212
`t.strictSame(MANIFEST_REQUEST, ['npm@latest', 'npm@latest'])
`
208
213
`})
`
209
214
``
210
215
`t.test('major to current', async t => {
`
211
216
`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')
`
214
219
`t.strictSame(MANIFEST_REQUEST, ['npm@latest', 'npm@latest'])
`
215
220
`})
`
216
221
``