@@ -48,24 +48,26 @@ describe('usePackageComparison', () => {
4848
4949 describe ( 'lastUpdated facet' , ( ) => {
5050 it ( 'uses version-specific publish date, not time.modified' , async ( ) => {
51+ const registryData = {
52+ 'name' : 'test-package' ,
53+ 'dist-tags' : { latest : '2.0.0' } ,
54+ 'time' : {
55+ // This is the WRONG value - updated by metadata changes
56+ 'modified' : '2024-12-01T00:00:00.000Z' ,
57+ // This is the CORRECT value - actual publish date
58+ '2.0.0' : '2024-06-15T00:00:00.000Z' ,
59+ } ,
60+ 'license' : 'MIT' ,
61+ 'versions' : {
62+ '2.0.0' : { dist : { unpackedSize : 15000 } } ,
63+ } ,
64+ }
5165 vi . stubGlobal (
5266 '$fetch' ,
53- vi . fn ( ) . mockImplementation ( ( url : string ) => {
54- if ( url . startsWith ( 'https://registry.npmjs.org/' ) ) {
55- return Promise . resolve ( {
56- 'name' : 'test-package' ,
57- 'dist-tags' : { latest : '2.0.0' } ,
58- 'time' : {
59- // This is the WRONG value - updated by metadata changes
60- 'modified' : '2024-12-01T00:00:00.000Z' ,
61- // This is the CORRECT value - actual publish date
62- '2.0.0' : '2024-06-15T00:00:00.000Z' ,
63- } ,
64- 'license' : 'MIT' ,
65- 'versions' : {
66- '2.0.0' : { dist : { unpackedSize : 15000 } } ,
67- } ,
68- } )
67+ vi . fn ( ) . mockImplementation ( ( url : string , options ?: { baseURL ?: string } ) => {
68+ const fullUrl = options ?. baseURL ? `${ options . baseURL } ${ url } ` : url
69+ if ( fullUrl . startsWith ( 'https://registry.npmjs.org/' ) ) {
70+ return Promise . resolve ( registryData )
6971 }
7072 return Promise . resolve ( null )
7173 } ) ,
@@ -93,8 +95,9 @@ describe('usePackageComparison', () => {
9395 it ( 'stores version-specific time in metadata' , async ( ) => {
9496 vi . stubGlobal (
9597 '$fetch' ,
96- vi . fn ( ) . mockImplementation ( ( url : string ) => {
97- if ( url . startsWith ( 'https://registry.npmjs.org/' ) ) {
98+ vi . fn ( ) . mockImplementation ( ( url : string , options ?: { baseURL ?: string } ) => {
99+ const fullUrl = options ?. baseURL ? `${ options . baseURL } ${ url } ` : url
100+ if ( fullUrl . startsWith ( 'https://registry.npmjs.org/' ) ) {
98101 return Promise . resolve ( {
99102 'name' : 'test-package' ,
100103 'dist-tags' : { latest : '1.0.0' } ,
@@ -128,8 +131,9 @@ describe('usePackageComparison', () => {
128131 it ( 'marks packages not published in 2+ years as stale' , async ( ) => {
129132 vi . stubGlobal (
130133 '$fetch' ,
131- vi . fn ( ) . mockImplementation ( ( url : string ) => {
132- if ( url . startsWith ( 'https://registry.npmjs.org/' ) ) {
134+ vi . fn ( ) . mockImplementation ( ( url : string , options ?: { baseURL ?: string } ) => {
135+ const fullUrl = options ?. baseURL ? `${ options . baseURL } ${ url } ` : url
136+ if ( fullUrl . startsWith ( 'https://registry.npmjs.org/' ) ) {
133137 return Promise . resolve ( {
134138 'name' : 'old-package' ,
135139 'dist-tags' : { latest : '1.0.0' } ,
@@ -159,8 +163,9 @@ describe('usePackageComparison', () => {
159163 it ( 'marks recently published packages as neutral' , async ( ) => {
160164 vi . stubGlobal (
161165 '$fetch' ,
162- vi . fn ( ) . mockImplementation ( ( url : string ) => {
163- if ( url . startsWith ( 'https://registry.npmjs.org/' ) ) {
166+ vi . fn ( ) . mockImplementation ( ( url : string , options ?: { baseURL ?: string } ) => {
167+ const fullUrl = options ?. baseURL ? `${ options . baseURL } ${ url } ` : url
168+ if ( fullUrl . startsWith ( 'https://registry.npmjs.org/' ) ) {
164169 return Promise . resolve ( {
165170 'name' : 'fresh-package' ,
166171 'dist-tags' : { latest : '1.0.0' } ,
0 commit comments