From ed26c2ebea9924ab6fba6ed69b23d8add5d775f8 Mon Sep 17 00:00:00 2001 From: Chareice Date: Sat, 13 Apr 2024 20:45:12 +0800 Subject: [PATCH] fix: vitest config --- packages/core/test/vitest.mjs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/core/test/vitest.mjs b/packages/core/test/vitest.mjs index 74b64a962..06dde15a8 100644 --- a/packages/core/test/vitest.mjs +++ b/packages/core/test/vitest.mjs @@ -150,7 +150,27 @@ const defineClientConfig = () => { }; export const getFilterInclude = (isServer, isCoverage) => { - let filterFileOrDir = process.argv.slice(2).find((arg) => !arg.startsWith('-')); + let argv = process.argv + .slice(2); + + argv = argv + .filter((item, index) => { + if (!item.startsWith('-')) { + const pre = argv[index - 1]; + + if (pre && pre.startsWith('--') && !pre.includes('=')) { + return false; + } + + return true; + } + + return false; + }); + + + let filterFileOrDir = argv[0]; + if (!filterFileOrDir) return {}; const absPath = path.join(process.cwd(), filterFileOrDir); const isDir = fs.existsSync(absPath) && fs.statSync(absPath).isDirectory(); @@ -213,11 +233,13 @@ export const defineConfig = () => { ); const { isFile, include: filterInclude } = getFilterInclude(isServer); + if (filterInclude) { config.test.include = filterInclude; if (isFile) { // 减少收集的文件 config.test.exclude = []; + config.test.coverage = { enabled: false, }; @@ -240,5 +262,6 @@ export const defineConfig = () => { config.test.coverage.reportsDirectory = reportsDirectory; } + return config; };