2021-12-06 21:23:34 +08:00
|
|
|
|
import dotenv from 'dotenv';
|
2022-02-15 09:11:00 +08:00
|
|
|
|
import { existsSync } from 'fs';
|
|
|
|
|
import { resolve } from 'path';
|
2021-12-06 21:23:34 +08:00
|
|
|
|
import prettyFormat from 'pretty-format';
|
2022-02-15 09:11:00 +08:00
|
|
|
|
|
|
|
|
|
const envFile = existsSync(resolve(__dirname, '.env.test')) ? '.env.test' : '.env';
|
2021-12-06 21:23:34 +08:00
|
|
|
|
|
|
|
|
|
dotenv.config({
|
2022-02-15 09:11:00 +08:00
|
|
|
|
path: resolve(__dirname, envFile),
|
2021-12-06 21:23:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
global['prettyFormat'] = prettyFormat;
|
|
|
|
|
|
|
|
|
|
jest.setTimeout(300000);
|
|
|
|
|
|
|
|
|
|
// 把 console.error 转换成 error,方便断言
|
|
|
|
|
(() => {
|
|
|
|
|
const spy = jest.spyOn(console, 'error');
|
|
|
|
|
beforeAll(() => {
|
2022-02-15 09:54:57 +08:00
|
|
|
|
spy.mockImplementation((message) => {
|
2021-12-06 21:23:34 +08:00
|
|
|
|
console.log(message);
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
afterAll(() => {
|
|
|
|
|
spy.mockRestore();
|
|
|
|
|
});
|
|
|
|
|
})();
|
2022-02-15 09:54:57 +08:00
|
|
|
|
|