优化
This commit is contained in:
11
client/web/test/fileTransformer.js
Normal file
11
client/web/test/fileTransformer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
process(src, filename, config, options) {
|
||||
const code =
|
||||
'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
|
||||
|
||||
// return { code };
|
||||
return code;
|
||||
},
|
||||
};
|
||||
26
client/web/test/setup.js
Normal file
26
client/web/test/setup.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// mock
|
||||
jest.mock('tailchat-shared/i18n');
|
||||
jest.mock('tailchat-design/components/Icon', () => ({
|
||||
Icon: ({ icon }) => `[iconify icon="${icon}"]`,
|
||||
}));
|
||||
jest.mock('../src/components/Loadable');
|
||||
jest.mock('../src/components/UserName');
|
||||
|
||||
const ignoreErroMessages = [
|
||||
/Warning.*not wrapped in act/,
|
||||
/PluginManifest validation/,
|
||||
];
|
||||
|
||||
// https://github.com/testing-library/react-testing-library#suppressing-unnecessary-warnings-on-react-dom-168
|
||||
const originalError = console.error;
|
||||
console.error = (...args) => {
|
||||
if (ignoreErroMessages.some((re) => re.test(args[0]))) {
|
||||
return;
|
||||
}
|
||||
|
||||
originalError.call(console, ...args);
|
||||
};
|
||||
|
||||
// Mock location
|
||||
delete window.location;
|
||||
window.location = new URL('https://www.example.com/foo/index');
|
||||
24
client/web/test/utils/lazy.tsx
Normal file
24
client/web/test/utils/lazy.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import React, { Suspense } from 'react';
|
||||
import { sleep } from 'tailchat-shared';
|
||||
|
||||
/**
|
||||
* 在普通的组件上面加一个 Suspense
|
||||
*/
|
||||
export function renderWithSuspense(ui: React.ReactElement) {
|
||||
return render(ui, {
|
||||
wrapper: (props) => (
|
||||
<Suspense fallback="JestLoading">{props.children}</Suspense>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染一个懒加载组件
|
||||
*/
|
||||
export async function renderLazy(ui: React.ReactElement, ms = 400) {
|
||||
const wrapper = renderWithSuspense(ui);
|
||||
await sleep(ms);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
Reference in New Issue
Block a user