-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
30 lines (28 loc) · 746 Bytes
/
vitest.setup.ts
File metadata and controls
30 lines (28 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {beforeEach, vi} from 'vitest';
const originalFetch = global.fetch;
const fetchMock = vi.fn<typeof fetch>((...args) => {
const [url] = args;
if (url === '/__/firebase/init.json') {
return Promise.resolve(
new Response(
JSON.stringify({
apiKey: 'fakeApiKey',
projectId: 'solid-start-firebase-template',
}),
),
);
}
return originalFetch(...args);
});
vi.stubGlobal('fetch', fetchMock);
beforeEach(async () => {
// Reset firestore data
await originalFetch(
'http://localhost:8080/emulator/v1/projects/solid-start-firebase-template/databases/(default)/documents',
{
method: 'DELETE',
},
);
// Wait a bit for the deletion to complete
await new Promise((resolve) => setTimeout(resolve, 100));
});