Skip to content

Commit 767a042

Browse files
committed
reset module for each test
1 parent 25cc9b5 commit 767a042

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/modules/ConsoleEventTracker/sendPipeline.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import "fake-indexeddb/auto"
22
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest"
33
import 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
68
vi.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

4144
let fetchSpy: MockInstance<
4245
[input: RequestInfo | URL, init?: RequestInit],
@@ -75,6 +78,10 @@ const mockFullCycle = () => {
7578
let originalBackoff: typeof _internals.backoff
7679

7780
beforeEach(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

9299
afterEach(() => {
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

Comments
 (0)