forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.ts
35 lines (30 loc) · 987 Bytes
/
setup.ts
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
31
32
33
34
35
/* eslint-disable import/newline-after-import,import/first */
import '@testing-library/jest-dom';
import { theme } from 'antd';
// mock indexedDB to test with dexie
// refs: https://github.com/dumbmatter/fakeIndexedDB#dexie-and-other-indexeddb-api-wrappers
import 'fake-indexeddb/auto';
import React from 'react';
// only inject in the dom environment
if (
// not node runtime
typeof window !== 'undefined' &&
// not edge runtime
typeof (globalThis as any).EdgeRuntime !== 'string'
) {
// test with canvas
await import('vitest-canvas-mock');
}
// node runtime
if (typeof window === 'undefined') {
// test with polyfill crypto
const { Crypto } = await import('@peculiar/webcrypto');
Object.defineProperty(global, 'crypto', {
value: new Crypto(),
writable: true,
});
}
// remove antd hash on test
theme.defaultConfig.hashed = false;
// 将 React 设置为全局变量,这样就不需要在每个测试文件中导入它了
(global as any).React = React;