1
1
import { describe , expect , it } from 'vitest' ;
2
2
import type { AuditOutput , Issue } from '@code-pushup/models' ;
3
+ import { objectFromEntries } from '@code-pushup/utils' ;
4
+ import { RELEASE_TYPES } from './constants' ;
3
5
import {
4
6
calculateOutdatedScore ,
5
- getOutdatedLevel ,
6
7
outdatedResultToAuditOutput ,
7
8
outdatedToDisplayValue ,
8
9
outdatedToIssues ,
9
- splitPackageVersion ,
10
10
} from './transform' ;
11
- import { PackageVersion } from './types' ;
12
11
13
12
describe ( 'outdatedResultToAuditOutput' , ( ) => {
14
13
it ( 'should create an audit output' , ( ) => {
@@ -87,7 +86,7 @@ describe('outdatedResultToAuditOutput', () => {
87
86
{
88
87
name : 'nx' ,
89
88
current : '15.8.1' ,
90
- latest : '17.0.0-stable ' ,
89
+ latest : '17.0.0' ,
91
90
type : 'dependencies' ,
92
91
} ,
93
92
{
@@ -170,20 +169,54 @@ describe('outdatedResultToAuditOutput', () => {
170
169
} ) ;
171
170
} ) ;
172
171
173
- it ( 'should skip identical semantic versions with different label ' , ( ) => {
172
+ it ( 'should skip non-standard versions' , ( ) => {
174
173
expect (
175
174
outdatedResultToAuditOutput (
176
175
[
177
176
{
178
- name : 'cypress ' ,
179
- current : '13.7 .0-alpha' ,
180
- latest : '13.7.0-beta ' ,
177
+ name : 'memfs ' ,
178
+ current : '4.0 .0-alpha.2 ' ,
179
+ latest : 'exotic ' ,
181
180
type : 'devDependencies' ,
182
181
} ,
182
+ ] ,
183
+ 'npm' ,
184
+ 'optional' ,
185
+ ) ,
186
+ ) . toEqual < AuditOutput > ( {
187
+ slug : 'npm-outdated-optional' ,
188
+ score : 1 ,
189
+ value : 0 ,
190
+ displayValue : 'all dependencies are up to date' ,
191
+ } ) ;
192
+ } ) ;
193
+
194
+ it ( 'should identify and categorise pre-release tags' , ( ) => {
195
+ expect (
196
+ outdatedResultToAuditOutput (
197
+ [
183
198
{
184
- name : 'nx' ,
185
- current : '17.0.0-12' ,
186
- latest : '17.0.0-15' ,
199
+ name : 'esbuild' ,
200
+ current : '0.5.3' ,
201
+ latest : '0.6.0-alpha.1' ,
202
+ type : 'devDependencies' ,
203
+ } ,
204
+ {
205
+ name : 'nx-knip' ,
206
+ current : '0.0.5-5' ,
207
+ latest : '0.0.5-15' ,
208
+ type : 'devDependencies' ,
209
+ } ,
210
+ {
211
+ name : 'semver' ,
212
+ current : '7.6.0' ,
213
+ latest : '7.6.8-2' ,
214
+ type : 'devDependencies' ,
215
+ } ,
216
+ {
217
+ name : 'code-pushup' ,
218
+ current : '0.30.0' ,
219
+ latest : '1.0.0-alpha.1' ,
187
220
type : 'devDependencies' ,
188
221
} ,
189
222
] ,
@@ -193,8 +226,37 @@ describe('outdatedResultToAuditOutput', () => {
193
226
) . toEqual < AuditOutput > ( {
194
227
slug : 'npm-outdated-dev' ,
195
228
score : 1 ,
196
- value : 0 ,
197
- displayValue : 'all dependencies are up to date' ,
229
+ value : 4 ,
230
+ displayValue :
231
+ '4 outdated package versions (1 premajor, 1 preminor, 1 prepatch, 1 prerelease)' ,
232
+ details : {
233
+ issues : [
234
+ {
235
+ message : expect . stringContaining (
236
+ '`esbuild` requires a **preminor** update' ,
237
+ ) ,
238
+ severity : 'info' ,
239
+ } ,
240
+ {
241
+ message : expect . stringContaining (
242
+ '`nx-knip` requires a **prerelease** update' ,
243
+ ) ,
244
+ severity : 'info' ,
245
+ } ,
246
+ {
247
+ message : expect . stringContaining (
248
+ '`semver` requires a **prepatch** update' ,
249
+ ) ,
250
+ severity : 'info' ,
251
+ } ,
252
+ {
253
+ message : expect . stringContaining (
254
+ '`code-pushup` requires a **premajor** update' ,
255
+ ) ,
256
+ severity : 'info' ,
257
+ } ,
258
+ ] ,
259
+ } ,
198
260
} ) ;
199
261
} ) ;
200
262
} ) ;
@@ -210,27 +272,41 @@ describe('calculateOutdatedScore', () => {
210
272
} ) ;
211
273
212
274
describe ( 'outdatedToDisplayValue' , ( ) => {
275
+ const ZERO_STATS = objectFromEntries (
276
+ RELEASE_TYPES . map ( versionType => [ versionType , 0 ] ) ,
277
+ ) ;
278
+
213
279
it ( 'should display perfect value e for no outdated dependencies' , ( ) => {
214
- expect ( outdatedToDisplayValue ( { major : 0 , minor : 0 , patch : 0 } ) ) . toBe (
280
+ expect ( outdatedToDisplayValue ( ZERO_STATS ) ) . toBe (
215
281
'all dependencies are up to date' ,
216
282
) ;
217
283
} ) ;
218
284
219
285
it ( 'should explicitly state outdated dependencies' , ( ) => {
220
- expect ( outdatedToDisplayValue ( { major : 5 , minor : 2 , patch : 1 } ) ) . toBe (
221
- '8 outdated package versions (5 major, 2 minor, 1 patch)' ,
286
+ expect (
287
+ outdatedToDisplayValue ( {
288
+ major : 5 ,
289
+ premajor : 1 ,
290
+ minor : 2 ,
291
+ preminor : 2 ,
292
+ patch : 1 ,
293
+ prepatch : 1 ,
294
+ prerelease : 3 ,
295
+ } ) ,
296
+ ) . toBe (
297
+ '15 outdated package versions (5 major, 1 premajor, 2 minor, 2 preminor, 1 patch, 1 prepatch, 3 prerelease)' ,
222
298
) ;
223
299
} ) ;
224
300
225
301
it ( 'should only list version types that have outdated dependencies' , ( ) => {
226
- expect ( outdatedToDisplayValue ( { major : 2 , minor : 0 , patch : 3 } ) ) . toBe (
302
+ expect ( outdatedToDisplayValue ( { ... ZERO_STATS , major : 2 , patch : 3 } ) ) . toBe (
227
303
'5 outdated package versions (2 major, 3 patch)' ,
228
304
) ;
229
305
} ) ;
230
306
231
307
it ( 'should skip breakdown if only one version type is outdated' , ( ) => {
232
- expect ( outdatedToDisplayValue ( { major : 0 , minor : 4 , patch : 0 } ) ) . toBe (
233
- '4 minor outdated package versions' ,
308
+ expect ( outdatedToDisplayValue ( { ... ZERO_STATS , prerelease : 4 } ) ) . toBe (
309
+ '4 prerelease outdated package versions' ,
234
310
) ;
235
311
} ) ;
236
312
} ) ;
@@ -294,29 +370,3 @@ describe('outdatedToIssues', () => {
294
370
expect ( outdatedToIssues ( [ ] ) ) . toEqual ( [ ] ) ;
295
371
} ) ;
296
372
} ) ;
297
-
298
- describe ( 'getOutdatedLevel' , ( ) => {
299
- it ( 'should return outdated major version' , ( ) => {
300
- expect ( getOutdatedLevel ( '4.2.1' , '5.2.0' ) ) . toBe ( 'major' ) ;
301
- } ) ;
302
-
303
- it ( 'should prioritise higher outdated version level' , ( ) => {
304
- expect ( getOutdatedLevel ( '6.2.1' , '6.3.2' ) ) . toBe ( 'minor' ) ;
305
- } ) ;
306
- } ) ;
307
-
308
- describe ( 'splitPackageVersion' , ( ) => {
309
- it ( 'should split version into major, minor and patch' , ( ) => {
310
- expect ( splitPackageVersion ( '0.32.4' ) ) . toEqual < PackageVersion > ( {
311
- major : 0 ,
312
- minor : 32 ,
313
- patch : 4 ,
314
- } ) ;
315
- } ) ;
316
-
317
- it ( 'should throw for an incomplete version' , ( ) => {
318
- expect ( ( ) => splitPackageVersion ( '5.0' ) ) . toThrow (
319
- 'Invalid version description 5.0' ,
320
- ) ;
321
- } ) ;
322
- } ) ;
0 commit comments