test: fix client-v2 test routing

This commit is contained in:
Zeke Zhang
2026-04-28 20:37:23 +08:00
parent 3827ed0145
commit 052b9d1ef8
2 changed files with 50 additions and 2 deletions
@@ -0,0 +1,45 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { afterEach, describe, expect, test } from 'vitest';
import { defineConfig, getFilterInclude } from '../../vitest.mjs';
const originalArgv = [...process.argv];
const originalTestEnv = process.env.TEST_ENV;
afterEach(() => {
process.argv = [...originalArgv];
if (originalTestEnv === undefined) {
delete process.env.TEST_ENV;
return;
}
process.env.TEST_ENV = originalTestEnv;
});
describe('vitest test routing', () => {
test('server-side config excludes plugin client-v2 tests', () => {
process.env.TEST_ENV = 'server-side';
process.argv = ['node', 'vitest'];
const config = defineConfig();
expect(config.test.exclude).toContain('packages/**/src/client-v2/**/*');
});
test('client-side package filter includes plugin client-v2 tests', () => {
process.argv = ['node', 'vitest', 'packages/plugins/@nocobase/plugin-acl'];
expect(getFilterInclude(false).include).toContain(
'packages/plugins/@nocobase/plugin-acl/src/client-v2/**/__tests__/**/*.{test,spec}.{ts,tsx}',
);
});
});
+5 -2
View File
@@ -10,6 +10,7 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const CORE_CLIENT_PACKAGES = ['sdk', 'client', 'client-v2', 'flow-engine'];
const PLUGIN_CLIENT_PACKAGES = ['client', 'client-v2'];
// 按路径填写要跳过服务端测试的插件目录(相对仓库根目录)
const skipPluginPaths = [
'packages/plugins/@nocobase/plugin-audit-logs',
@@ -114,7 +115,7 @@ const defineCommonConfig = () => {
function getExclude(isServer) {
return [
`packages/core/${isServer ? '' : '!'}(${CORE_CLIENT_PACKAGES.join('|')})/**/*`,
`packages/**/src/${isServer ? 'client' : 'server'}/**/*`,
...(isServer ? PLUGIN_CLIENT_PACKAGES : ['server']).map((dir) => `packages/**/src/${dir}/**/*`),
];
}
@@ -220,7 +221,9 @@ export const getFilterInclude = (isServer, isCoverage) => {
// 插件目录,区分 client 和 server
return {
include: [`${filterFileOrDir}/src/${isServer ? 'server' : 'client'}/${suffix}`],
include: isServer
? [`${filterFileOrDir}/src/server/${suffix}`]
: PLUGIN_CLIENT_PACKAGES.map((dir) => `${filterFileOrDir}/src/${dir}/${suffix}`),
};
};