11import "fake-indexeddb/auto"
22import { vi , describe , it , expect , beforeEach , afterEach } from "vitest"
33import type { MockInstance } from "vitest"
4+ import type { _internals as InternalsType } from "./sendPipeline"
5+ import type { db as DbType } from "../../store/db"
46
57// Stub browser globals before db.ts singleton is created
68vi . hoisted ( ( ) => {
@@ -35,8 +37,9 @@ vi.mock("../../consts", () => ({
3537 API : "https://test.questdb.io" ,
3638} ) )
3739
38- import { db } from "../../store/db"
39- import { _internals , startPipeline , stopPipeline } from "./sendPipeline"
40+ let _internals : typeof InternalsType
41+ let stopPipeline : ( ) => void
42+ let db : typeof DbType
4043
4144let fetchSpy : MockInstance <
4245 [ input : RequestInfo | URL , init ?: RequestInit ] ,
@@ -75,6 +78,10 @@ const mockFullCycle = () => {
7578let originalBackoff : typeof _internals . backoff
7679
7780beforeEach ( async ( ) => {
81+ vi . resetModules ( )
82+ ; ( { db } = await import ( "../../store/db" ) )
83+ ; ( { _internals, stopPipeline } = await import ( "./sendPipeline" ) )
84+
7885 await db . events . clear ( )
7986 _internals . resetState ( )
8087 fetchSpy = vi
@@ -90,7 +97,7 @@ beforeEach(async () => {
9097} )
9198
9299afterEach ( ( ) => {
93- stopPipeline ( )
100+ stopPipeline ?. ( )
94101 _internals . backoff = originalBackoff
95102 vi . restoreAllMocks ( )
96103} )
@@ -398,7 +405,9 @@ describe("run — max attempts", () => {
398405 const url =
399406 typeof input === "string"
400407 ? input
401- : ( ( input as Request ) . url ?? String ( input ) )
408+ : input instanceof URL
409+ ? input . toString ( )
410+ : input . url
402411 if ( url . includes ( "console-events-config" ) ) {
403412 return Promise . resolve (
404413 new Response ( JSON . stringify ( { lastUpdated : null } ) , {
0 commit comments