@gsc-basic/vitest-config 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +4 -4
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
- `plugins`: 框架插件开关(`vue`、`vueJsx`)
|
|
43
43
|
- `resolve`: 直接透传 Vitest/Vite 官方 `resolve` 配置
|
|
44
44
|
- `css`: 透传 Vite `css` 配置
|
|
45
|
-
- `test`: Vitest 运行时配置(`environment`、`setupFiles`、`coverage`、`depsInline`、`ui` 等)
|
|
45
|
+
- `test`: Vitest 运行时配置(`environment`、`setupFiles`、`coverage`、`depsInline`、`ui`、`sonarReporter` 等)
|
|
46
46
|
|
|
47
47
|
当前包开箱即用仅保证 `node` 与 `happy-dom` 两类测试环境,这也与内置预设和依赖保持一致。
|
|
48
48
|
|
|
@@ -111,6 +111,31 @@ export default defineVitestConfig({
|
|
|
111
111
|
});
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
### SonarQube 测试执行报告
|
|
115
|
+
|
|
116
|
+
设置 `test.sonarReporter` 后,测试结果会生成 SonarQube Generic Execution XML;终端仍保留 Vitest 默认报告器输出。
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
import { defineVitestConfig } from '@gsc-basic/vitest-config';
|
|
120
|
+
|
|
121
|
+
export default defineVitestConfig({
|
|
122
|
+
test: {
|
|
123
|
+
sonarReporter: {
|
|
124
|
+
outputFile: 'reports/sonar-report.xml',
|
|
125
|
+
silent: true,
|
|
126
|
+
},
|
|
127
|
+
coverage: true,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`sonarReporter: true` 使用默认输出路径 `sonar-report.xml`。在 `sonar-project.properties` 中配置:
|
|
133
|
+
|
|
134
|
+
```properties
|
|
135
|
+
sonar.testExecutionReportPaths=reports/sonar-report.xml
|
|
136
|
+
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
137
|
+
```
|
|
138
|
+
|
|
114
139
|
## 最短迁移清单(从业务仓库迁移到本包)
|
|
115
140
|
|
|
116
141
|
1. 安装依赖:在业务仓库新增 `@gsc-basic/vitest-config`,并确保保留 `vite`、`vitest`。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import { UserConfig } from "vite";
|
|
3
|
-
|
|
4
3
|
//#region src/typing.d.ts
|
|
5
4
|
type GscVitestPreset = 'node' | 'web' | 'vue';
|
|
5
|
+
interface GscVitestSonarReporterOptions {
|
|
6
|
+
outputFile?: string;
|
|
7
|
+
silent?: boolean;
|
|
8
|
+
onWritePath?: (path: string) => string;
|
|
9
|
+
}
|
|
6
10
|
interface GscVitestCoverageOptions {
|
|
7
11
|
provider?: 'v8';
|
|
8
12
|
reporter?: string[];
|
|
@@ -26,6 +30,7 @@ interface GscVitestTestOptions {
|
|
|
26
30
|
depsExternal?: Array<string | RegExp>;
|
|
27
31
|
coverage?: boolean | GscVitestCoverageOptions;
|
|
28
32
|
ui?: boolean;
|
|
33
|
+
sonarReporter?: boolean | GscVitestSonarReporterOptions;
|
|
29
34
|
}
|
|
30
35
|
interface GscVitestOptions {
|
|
31
36
|
preset?: GscVitestPreset;
|
|
@@ -42,4 +47,4 @@ declare function createVitestConfig(options?: GscVitestOptions): GscVitestConfig
|
|
|
42
47
|
declare function defineVitestConfig(options?: GscVitestOptions, overrides?: GscVitestConfig): GscVitestConfig;
|
|
43
48
|
declare function mergeVitestConfig(baseConfig: GscVitestConfig, overrideConfig: GscVitestConfig): GscVitestConfig;
|
|
44
49
|
//#endregion
|
|
45
|
-
export { type GscVitestConfig, type GscVitestCoverageOptions, type GscVitestOptions, type GscVitestPluginOptions, type GscVitestPreset, type GscVitestTestOptions, createVitestConfig, defineVitestConfig, mergeVitestConfig };
|
|
50
|
+
export { type GscVitestConfig, type GscVitestCoverageOptions, type GscVitestOptions, type GscVitestPluginOptions, type GscVitestPreset, type GscVitestSonarReporterOptions, type GscVitestTestOptions, createVitestConfig, defineVitestConfig, mergeVitestConfig };
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,8 @@ You shall not disclose such Confidential Information and shall use it only in
|
|
|
7
7
|
accordance with the terms of the license agreement.
|
|
8
8
|
|
|
9
9
|
--- Build Info ---
|
|
10
|
-
Version: 1.0.
|
|
11
|
-
Build Time: 2026/
|
|
12
|
-
Build Commit:
|
|
10
|
+
Version: 1.0.2
|
|
11
|
+
Build Time: 2026/8/4 15:34:44
|
|
12
|
+
Build Commit: ba8eb8fba455b41ceefde75e728d23e393447d7b
|
|
13
13
|
*/
|
|
14
|
-
import e from"@vitejs/plugin-vue";import t from"@vitejs/plugin-vue-jsx";import{configDefaults as n,defineConfig as r,mergeConfig as i}from"vitest/config";const a={provider:`v8`,reporter:[`text`,`lcov`]},o={node:{environment:`node`,css:!1,vue:!1,vueJsx:!1},web:{environment:`happy-dom`,css:!0,vue:!1,vueJsx:!1},vue:{environment:`happy-dom`,css:!0,vue:!0,vueJsx:!0}};function s(e){if(e!==!1)return e===!0||e==null?a:{...a,...e}}function c(n,r){let i=[],a=o[r],s=n.plugins?.vue??a.vue,c=n.plugins?.vueJsx??a.vueJsx;return s&&i.push(e()),c&&i.push(t()),i}function l(e={}){let t=e.preset||`node`,r=o[t];return{plugins:c(e,t),root:e.root,resolve:e.resolve,...e.css?{css:e.css}:{},test:{environment:e.test?.environment||r.environment,includeSource:e.test?.includeSource,exclude:[...n.exclude,...e.test?.exclude||[]],setupFiles:e.test?.setupFiles||[],css:e.test?.css??r.css,globals:e.test?.globals,passWithNoTests:e.test?.passWithNoTests,ui:e.test?.ui,server:{deps:{inline:e.test?.depsInline,external:e.test?.depsExternal}},coverage:s(e.test?.coverage)}}}function
|
|
14
|
+
import e from"@vitejs/plugin-vue";import t from"@vitejs/plugin-vue-jsx";import{configDefaults as n,defineConfig as r,mergeConfig as i}from"vitest/config";const a={provider:`v8`,reporter:[`text`,`lcov`]},o={node:{environment:`node`,css:!1,vue:!1,vueJsx:!1},web:{environment:`happy-dom`,css:!0,vue:!1,vueJsx:!1},vue:{environment:`happy-dom`,css:!0,vue:!0,vueJsx:!0}};function s(e){if(e!==!1)return e===!0||e==null?a:{...a,...e}}function c(n,r){let i=[],a=o[r],s=n.plugins?.vue??a.vue,c=n.plugins?.vueJsx??a.vueJsx;return s&&i.push(e()),c&&i.push(t()),i}function l(e){let t=e.test?.sonarReporter;if(t)return[`default`,[`vitest-sonar-reporter`,{outputFile:`reports/vitest-sonar-report.xml`,...t===!0?{}:t}]]}function u(e={}){let t=e.preset||`node`,r=o[t];return{plugins:c(e,t),root:e.root,resolve:e.resolve,...e.css?{css:e.css}:{},test:{environment:e.test?.environment||r.environment,includeSource:e.test?.includeSource,exclude:[...n.exclude,...e.test?.exclude||[]],setupFiles:e.test?.setupFiles||[],css:e.test?.css??r.css,globals:e.test?.globals,passWithNoTests:e.test?.passWithNoTests,ui:e.test?.ui,reporters:l(e),server:{deps:{inline:e.test?.depsInline,external:e.test?.depsExternal}},coverage:s(e.test?.coverage)}}}function d(e={},t={}){return r(i(u(e),t))}function f(e,t){return i(e,t)}export{u as createVitestConfig,d as defineVitestConfig,f as mergeVitestConfig};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gsc-basic/vitest-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "Vitest Config for GSC Basic Service",
|
|
6
6
|
"author": "Lenovo SSG BASD <-GSC_Scaffolding_Support@lenovo.com>",
|
|
7
7
|
"license": "LicenseRef-Proprietary",
|
|
@@ -29,15 +29,16 @@
|
|
|
29
29
|
"./dist"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"vite": "^8.0
|
|
33
|
-
"vitest": "^4.1.
|
|
32
|
+
"vite": "^8.2.0",
|
|
33
|
+
"vitest": "^4.1.10"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
37
|
-
"@vitejs/plugin-vue-jsx": "^5.1.
|
|
38
|
-
"@vitest/coverage-v8": "^4.1.
|
|
39
|
-
"@vitest/ui": "^4.1.
|
|
40
|
-
"happy-dom": "^20.
|
|
36
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
37
|
+
"@vitejs/plugin-vue-jsx": "^5.1.6",
|
|
38
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
39
|
+
"@vitest/ui": "^4.1.10",
|
|
40
|
+
"happy-dom": "^20.11.1",
|
|
41
|
+
"vitest-sonar-reporter": "^3.0.0"
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "tsdown",
|