This commit is contained in:
2026-04-25 16:36:34 +08:00
commit db90e7579b
1876 changed files with 189777 additions and 0 deletions

View 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
View 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');

View 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;
}