@@ -5,10 +5,16 @@ import { join } from "node:path"
55import { createDocsFetcher } from "../../../src/docs-fetcher.js"
66
77describe ( "Cache Status Tracking" , ( ) => {
8- const testDbPath = join ( tmpdir ( ) , `test-cache-status- ${ Date . now ( ) } .db` )
8+ let testDbPath : string
99 let fetcher : ReturnType < typeof createDocsFetcher >
1010
1111 beforeEach ( ( ) => {
12+ // Create unique database path for each test to avoid conflicts
13+ testDbPath = join (
14+ tmpdir ( ) ,
15+ `test-cache-status-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 9 ) } .db`
16+ )
17+
1218 // Create fetcher with persistent database for testing
1319 fetcher = createDocsFetcher ( {
1420 dbPath : testDbPath ,
@@ -47,7 +53,7 @@ describe("Cache Status Tracking", () => {
4753 expect ( result . fromCache ) . toBe ( false )
4854 expect ( result . data ) . toBeDefined ( )
4955 expect ( result . data . root ) . toBeDefined ( ) // Basic validation of rustdoc JSON structure
50- } )
56+ } , 10000 )
5157
5258 it ( "should return fromCache: true on subsequent fetch" , async ( ) => {
5359 // First fetch - should hit the network
@@ -60,7 +66,7 @@ describe("Cache Status Tracking", () => {
6066
6167 // Data should be identical
6268 expect ( secondResult . data ) . toEqual ( firstResult . data )
63- } )
69+ } , 10000 )
6470
6571 it ( "should persist cache across fetcher instances" , async ( ) => {
6672 // First fetcher instance
@@ -81,7 +87,7 @@ describe("Cache Status Tracking", () => {
8187 expect ( result2 . data ) . toEqual ( result1 . data )
8288
8389 fetcher2 . close ( )
84- } )
90+ } , 10000 )
8591
8692 it ( "should handle different versions separately" , async ( ) => {
8793 // Fetch latest version
@@ -99,7 +105,7 @@ describe("Cache Status Tracking", () => {
99105 // Fetch the specific version again - should also be cached
100106 const versionAgain = await fetcher . fetchCrateJson ( "tinc" , "0.1.6" )
101107 expect ( versionAgain . fromCache ) . toBe ( true )
102- } )
108+ } , 15000 )
103109
104110 it ( "should track cache misses for non-existent crates" , async ( ) => {
105111 try {
@@ -118,7 +124,7 @@ describe("Cache Status Tracking", () => {
118124 expect ( secondError ) . toBeDefined ( )
119125 }
120126 }
121- } )
127+ } , 10000 )
122128
123129 it ( "should work with in-memory cache" , async ( ) => {
124130 // Create fetcher with in-memory cache
@@ -135,7 +141,7 @@ describe("Cache Status Tracking", () => {
135141 expect ( secondResult . fromCache ) . toBe ( true )
136142
137143 memoryFetcher . close ( )
138- } )
144+ } , 10000 )
139145
140146 it ( "should respect cache TTL" , async ( ) => {
141147 // Create fetcher with very short TTL
@@ -162,5 +168,5 @@ describe("Cache Status Tracking", () => {
162168 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
163169 }
164170 rmSync ( join ( tmpdir ( ) , `test-ttl-${ Date . now ( ) } .db` ) , { force : true } )
165- } )
171+ } , 10000 )
166172} )
0 commit comments