mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 15:48:06 +00:00
261d4c4137
* chore: use vitest to replace jest * chore: support vitest * feat: vitest 1.0 * fix: test * chore: yarn.lock * chore: github actions * fix: test * fix: test * fix: test * fix: test * fix: jest.fn * fix: require * fix: test * fix: build * fix: test * fix: test * fix: test * fix: test * fix: test * fix: test * fix: test * fix: dynamic import * fix: bug * chore: yarn run test command * chore: package.json * chore: package.json * chore: vite 5 * fix: fix variable test * fix: import json * feat: initEnv * fix: env.APP_ENV_PATH * chore: get package json * fix: remove GlobalThmeProvider * chore: update snap * chore: test env * chore: test env * chore: import module * chore: jest * fix: load package json * chore: test * fix: bug * chore: test * chore: test * chore: test * chore: test * chore: test * fix: import file in windows * chore: import module with absolute file path * fix: test error * test: update snapshot * chore: update yarn.lock * fix: front-end tests do not include utils folder * refactor: use vitest-dom * fix: fix build * fix: test error * fix: change to vitest.config.mts * fix: types error * fix: types error * fix: types error * fix: error * fix: test * chore: test * fix: test package * feat: update dependencies * refactor: test * fix: error * fix: error * fix: __dirname is not defined in ES module scope * fix: allow only * fix: error * fix: error * fix: error * fix: create-app * fix: install-deps * feat: update docs --------- Co-authored-by: chenos <chenlinxh@gmail.com> Co-authored-by: dream2023 <1098626505@qq.com> Co-authored-by: Zeke Zhang <958414905@qq.com>
111 lines
3.3 KiB
JavaScript
111 lines
3.3 KiB
JavaScript
import react from '@vitejs/plugin-react';
|
|
import fs from 'fs';
|
|
import path, { resolve } from 'path';
|
|
import { URL } from 'url';
|
|
import { defineConfig as vitestConfig } from 'vitest/config';
|
|
|
|
const __dirname = new URL('.', import.meta.url).pathname;
|
|
|
|
const relativePathToAbsolute = (relativePath) => {
|
|
return path.resolve(process.cwd(), relativePath);
|
|
};
|
|
|
|
function tsConfigPathsToAlias() {
|
|
const json = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './tsconfig.paths.json'), { encoding: 'utf8' }));
|
|
const paths = json.compilerOptions.paths;
|
|
const alias = Object.keys(paths).reduce((acc, key) => {
|
|
if (key !== '@@/*') {
|
|
const value = paths[key][0];
|
|
acc.push({
|
|
find: key,
|
|
replacement: value,
|
|
});
|
|
}
|
|
return acc;
|
|
}, []);
|
|
alias.unshift({
|
|
find: '@nocobase/utils/plugin-symlink',
|
|
replacement: 'node_modules/@nocobase/utils/plugin-symlink.js',
|
|
});
|
|
return [
|
|
{ find: /^~antd\/(.*)/, replacement: 'antd/$1' },
|
|
...alias.map((item) => {
|
|
return {
|
|
...item,
|
|
replacement: relativePathToAbsolute(item.replacement),
|
|
};
|
|
}),
|
|
];
|
|
}
|
|
|
|
export const defineConfig = (config = {}) => {
|
|
return vitestConfig(
|
|
process.env.TEST_ENV === 'server-side'
|
|
? {
|
|
root: process.cwd(),
|
|
resolve: {
|
|
mainFields: ['module'],
|
|
},
|
|
test: {
|
|
globals: true,
|
|
setupFiles: resolve(__dirname, './setup/server.ts'),
|
|
alias: tsConfigPathsToAlias(),
|
|
include: ['packages/**/__tests__/**/*.test.ts'],
|
|
exclude: [
|
|
'**/node_modules/**',
|
|
'**/dist/**',
|
|
'**/lib/**',
|
|
'**/es/**',
|
|
'**/e2e/**',
|
|
'**/{vitest,commitlint}.config.*',
|
|
'packages/**/{dumi-theme-nocobase,sdk,client}/**/__tests__/**/*.{test,spec}.{ts,tsx}',
|
|
],
|
|
testTimeout: 300000,
|
|
bail: 1,
|
|
// 在 GitHub Actions 中不输出日志
|
|
silent: !!process.env.GITHUB_ACTIONS,
|
|
// poolOptions: {
|
|
// threads: {
|
|
// singleThread: process.env.SINGLE_THREAD == 'false' ? false : true,
|
|
// },
|
|
// },
|
|
},
|
|
}
|
|
: {
|
|
plugins: [react()],
|
|
resolve: {
|
|
mainFields: ['module'],
|
|
},
|
|
define: {
|
|
'process.env.__TEST__': true,
|
|
'process.env.__E2E__': false,
|
|
},
|
|
test: {
|
|
globals: true,
|
|
setupFiles: resolve(__dirname, './setup/client.ts'),
|
|
environment: 'jsdom',
|
|
css: false,
|
|
alias: tsConfigPathsToAlias(),
|
|
include: ['packages/**/{dumi-theme-nocobase,sdk,client}/**/__tests__/**/*.{test,spec}.{ts,tsx}'],
|
|
exclude: [
|
|
'**/node_modules/**',
|
|
'**/dist/**',
|
|
'**/lib/**',
|
|
'**/es/**',
|
|
'**/e2e/**',
|
|
'**/__e2e__/**',
|
|
'**/{vitest,commitlint}.config.*',
|
|
],
|
|
testTimeout: 300000,
|
|
// 在 GitHub Actions 中不输出日志
|
|
silent: !!process.env.GITHUB_ACTIONS,
|
|
server: {
|
|
deps: {
|
|
inline: ['@juggle/resize-observer', 'clsx'],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
);
|
|
};
|