11import { describe , expect , it } from 'vitest' ;
22import type { AuditOutput , Issue } from '@code-pushup/models' ;
3+ import { objectFromEntries } from '@code-pushup/utils' ;
4+ import { RELEASE_TYPES } from './constants' ;
35import {
46 calculateOutdatedScore ,
5- getOutdatedLevel ,
67 outdatedResultToAuditOutput ,
78 outdatedToDisplayValue ,
89 outdatedToIssues ,
9- splitPackageVersion ,
1010} from './transform' ;
11- import { PackageVersion } from './types' ;
1211
1312describe ( 'outdatedResultToAuditOutput' , ( ) => {
1413 it ( 'should create an audit output' , ( ) => {
@@ -87,7 +86,7 @@ describe('outdatedResultToAuditOutput', () => {
8786 {
8887 name : 'nx' ,
8988 current : '15.8.1' ,
90- latest : '17.0.0-stable ' ,
89+ latest : '17.0.0' ,
9190 type : 'dependencies' ,
9291 } ,
9392 {
@@ -170,20 +169,54 @@ describe('outdatedResultToAuditOutput', () => {
170169 } ) ;
171170 } ) ;
172171
173- it ( 'should skip identical semantic versions with different label ' , ( ) => {
172+ it ( 'should skip non-standard versions' , ( ) => {
174173 expect (
175174 outdatedResultToAuditOutput (
176175 [
177176 {
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 ' ,
181180 type : 'devDependencies' ,
182181 } ,
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+ [
183198 {
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' ,
187220 type : 'devDependencies' ,
188221 } ,
189222 ] ,
@@ -193,8 +226,37 @@ describe('outdatedResultToAuditOutput', () => {
193226 ) . toEqual < AuditOutput > ( {
194227 slug : 'npm-outdated-dev' ,
195228 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+ } ,
198260 } ) ;
199261 } ) ;
200262} ) ;
@@ -210,27 +272,41 @@ describe('calculateOutdatedScore', () => {
210272} ) ;
211273
212274describe ( 'outdatedToDisplayValue' , ( ) => {
275+ const ZERO_STATS = objectFromEntries (
276+ RELEASE_TYPES . map ( versionType => [ versionType , 0 ] ) ,
277+ ) ;
278+
213279 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 (
215281 'all dependencies are up to date' ,
216282 ) ;
217283 } ) ;
218284
219285 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)' ,
222298 ) ;
223299 } ) ;
224300
225301 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 (
227303 '5 outdated package versions (2 major, 3 patch)' ,
228304 ) ;
229305 } ) ;
230306
231307 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' ,
234310 ) ;
235311 } ) ;
236312} ) ;
@@ -294,29 +370,3 @@ describe('outdatedToIssues', () => {
294370 expect ( outdatedToIssues ( [ ] ) ) . toEqual ( [ ] ) ;
295371 } ) ;
296372} ) ;
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