@gsc-basic/vitest-config 1.0.2 → 1.1.1

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 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` 使用默认输出路径 `reports/vitest-sonar-report.xml`。在 `sonar-project.properties` 中配置:
133
+
134
+ ```properties
135
+ sonar.testExecutionReportPaths=reports/vitest-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
@@ -2,6 +2,11 @@
2
2
  import { UserConfig } from "vite";
3
3
  //#region src/typing.d.ts
4
4
  type GscVitestPreset = 'node' | 'web' | 'vue';
5
+ interface GscVitestSonarReporterOptions {
6
+ outputFile?: string;
7
+ silent?: boolean;
8
+ onWritePath?: (path: string) => string;
9
+ }
5
10
  interface GscVitestCoverageOptions {
6
11
  provider?: 'v8';
7
12
  reporter?: string[];
@@ -25,6 +30,7 @@ interface GscVitestTestOptions {
25
30
  depsExternal?: Array<string | RegExp>;
26
31
  coverage?: boolean | GscVitestCoverageOptions;
27
32
  ui?: boolean;
33
+ sonarReporter?: boolean | GscVitestSonarReporterOptions;
28
34
  }
29
35
  interface GscVitestOptions {
30
36
  preset?: GscVitestPreset;
@@ -41,4 +47,4 @@ declare function createVitestConfig(options?: GscVitestOptions): GscVitestConfig
41
47
  declare function defineVitestConfig(options?: GscVitestOptions, overrides?: GscVitestConfig): GscVitestConfig;
42
48
  declare function mergeVitestConfig(baseConfig: GscVitestConfig, overrideConfig: GscVitestConfig): GscVitestConfig;
43
49
  //#endregion
44
- 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.1
11
- Build Time: 2026/7/24 13:48:38
12
- Build Commit: bf5044df25fefa2b374b5dfa6cd533cebaf4f662
10
+ Version: 1.1.0
11
+ Build Time: 2026/8/4 18:05:54
12
+ Build Commit: ab3937783db167b580608d7f7120bf4e9553b4b5
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 u(e={},t={}){return r(i(l(e),t))}function d(e,t){return i(e,t)}export{l as createVitestConfig,u as defineVitestConfig,d as mergeVitestConfig};
14
+ import{createRequire as e}from"node:module";import t from"@vitejs/plugin-vue";import n from"@vitejs/plugin-vue-jsx";import{configDefaults as r,defineConfig as i,mergeConfig as a}from"vitest/config";const o={provider:`v8`,reporter:[`text`,`lcov`]},s=e(import.meta.url);function c(){try{return s.resolve(`vitest-sonar-reporter`)}catch{return`vitest-sonar-reporter`}}const l={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 u(e){if(e!==!1)return e===!0||e==null?o:{...o,...e}}function d(e,r){let i=[],a=l[r],o=e.plugins?.vue??a.vue,s=e.plugins?.vueJsx??a.vueJsx;return o&&i.push(t()),s&&i.push(n()),i}function f(e){let t=e.test?.sonarReporter;if(t)return[`default`,[c(),{outputFile:`reports/vitest-sonar-report.xml`,...t===!0?{}:t}]]}function p(e={}){let t=e.preset||`node`,n=l[t],i=f(e);return{plugins:d(e,t),root:e.root,resolve:e.resolve,...e.css?{css:e.css}:{},test:{environment:e.test?.environment||n.environment,includeSource:e.test?.includeSource,exclude:[...r.exclude,...e.test?.exclude||[]],setupFiles:e.test?.setupFiles||[],css:e.test?.css??n.css,globals:e.test?.globals,passWithNoTests:e.test?.passWithNoTests,ui:e.test?.ui,...i?{reporters:i}:{},server:{deps:{inline:e.test?.depsInline,external:e.test?.depsExternal}},coverage:u(e.test?.coverage)}}}function m(e={},t={}){return i(a(p(e),t))}function h(e,t){return a(e,t)}export{p as createVitestConfig,m as defineVitestConfig,h 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.2",
4
+ "version": "1.1.1",
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,7 +29,7 @@
29
29
  "./dist"
30
30
  ],
31
31
  "peerDependencies": {
32
- "vite": "^8.1.5",
32
+ "vite": "^8.2.0",
33
33
  "vitest": "^4.1.10"
34
34
  },
35
35
  "dependencies": {
@@ -37,7 +37,8 @@
37
37
  "@vitejs/plugin-vue-jsx": "^5.1.6",
38
38
  "@vitest/coverage-v8": "^4.1.10",
39
39
  "@vitest/ui": "^4.1.10",
40
- "happy-dom": "^20.11.1"
40
+ "happy-dom": "^20.11.1",
41
+ "vitest-sonar-reporter": "^3.0.0"
41
42
  },
42
43
  "scripts": {
43
44
  "build": "tsdown",