@gsc-basic/vitest-config 1.1.1 → 1.2.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 CHANGED
@@ -15,10 +15,14 @@
15
15
  - `vite`
16
16
  - `vitest`
17
17
 
18
+ `vitest-sonar-reporter` 已由本包内置并在运行时自动解析,使用方项目无需重复声明该依赖。
19
+
18
20
  如需 Vue 组件测试,请在使用方项目中显式安装 `@vue/test-utils`。
19
21
 
20
22
  如需 UI 模式(`vitest --ui`),可直接使用,无需在使用方项目中额外安装 `@vitest/ui`。
21
23
 
24
+ 覆盖率默认使用 V8 provider。需要对 Vue SFC 或复杂转换链路使用 Istanbul 插桩时,可在 `coverage.provider` 显式设置为 `istanbul`,无需在使用方项目重复安装 coverage provider。
25
+
22
26
  ## API
23
27
 
24
28
  ### createVitestConfig(options)
@@ -44,6 +48,11 @@
44
48
  - `css`: 透传 Vite `css` 配置
45
49
  - `test`: Vitest 运行时配置(`environment`、`setupFiles`、`coverage`、`depsInline`、`ui`、`sonarReporter` 等)
46
50
 
51
+ 其中 `test.sonarReporter` 支持两种形式:
52
+
53
+ - `true`: 启用 SonarQube Generic Execution 报告,输出到默认路径 `reports/vitest-sonar-report.xml`
54
+ - 对象: 透传 `outputFile`、`silent`、`onWritePath` 进行细粒度配置
55
+
47
56
  当前包开箱即用仅保证 `node` 与 `happy-dom` 两类测试环境,这也与内置预设和依赖保持一致。
48
57
 
49
58
  ### 预设说明
@@ -111,10 +120,30 @@ export default defineVitestConfig({
111
120
  });
112
121
  ```
113
122
 
123
+ ### Istanbul 覆盖率
124
+
125
+ V8 是默认 provider。若项目将未执行的 Vue SFC 纳入 `coverage.include`,且 V8 覆盖率重映射无法处理项目的转换链路,可切换到 Istanbul:
126
+
127
+ ```js
128
+ import { defineVitestConfig } from '@gsc-basic/vitest-config';
129
+
130
+ export default defineVitestConfig({
131
+ preset: 'vue',
132
+ test: {
133
+ coverage: {
134
+ provider: 'istanbul',
135
+ include: ['src/**/*.{ts,tsx,js,jsx,vue}'],
136
+ },
137
+ },
138
+ });
139
+ ```
140
+
114
141
  ### SonarQube 测试执行报告
115
142
 
116
143
  设置 `test.sonarReporter` 后,测试结果会生成 SonarQube Generic Execution XML;终端仍保留 Vitest 默认报告器输出。
117
144
 
145
+ 在 pnpm 场景下,包内部会优先解析 reporter 的绝对路径,避免业务仓库出现 `Failed to load custom Reporter from vitest-sonar-reporter`。
146
+
118
147
  ```js
119
148
  import { defineVitestConfig } from '@gsc-basic/vitest-config';
120
149
 
@@ -163,3 +192,5 @@ sonar.javascript.lcov.reportPaths=coverage/lcov.info
163
192
 
164
193
  - 测试代码中直接使用到的库,请在使用方项目显式声明(如 `@vue/test-utils`)。
165
194
  - `test.environment` 当前仅建议使用 `node` 或 `happy-dom`,包本身未内置 `jsdom`、`edge-runtime` 相关支持。
195
+ - `coverage.provider` 支持 `v8` 与 `istanbul`,默认使用 `v8`。
196
+ - 如遇到历史项目本地仍报 reporter 加载错误,优先升级 `@gsc-basic/vitest-config` 到包含该修复的版本,而不是在业务仓库新增 `vitest-sonar-reporter` 直连依赖。
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ interface GscVitestSonarReporterOptions {
8
8
  onWritePath?: (path: string) => string;
9
9
  }
10
10
  interface GscVitestCoverageOptions {
11
- provider?: 'v8';
11
+ provider?: 'v8' | 'istanbul';
12
12
  reporter?: string[];
13
13
  include?: string[];
14
14
  exclude?: string[];
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.1.0
11
- Build Time: 2026/8/4 18:05:54
12
- Build Commit: ab3937783db167b580608d7f7120bf4e9553b4b5
10
+ Version: 1.1.1
11
+ Build Time: 2026/8/6 11:00:13
12
+ Build Commit: 955303b2115867d08e15eaab7245a240add5622e
13
13
  */
14
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.1.1",
4
+ "version": "1.2.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,12 +29,19 @@
29
29
  "./dist"
30
30
  ],
31
31
  "peerDependencies": {
32
+ "@vue/test-utils": "^2.4.11",
32
33
  "vite": "^8.2.0",
33
34
  "vitest": "^4.1.10"
34
35
  },
36
+ "peerDependenciesMeta": {
37
+ "@vue/test-utils": {
38
+ "optional": true
39
+ }
40
+ },
35
41
  "dependencies": {
36
42
  "@vitejs/plugin-vue": "^6.0.8",
37
43
  "@vitejs/plugin-vue-jsx": "^5.1.6",
44
+ "@vitest/coverage-istanbul": "^4.1.10",
38
45
  "@vitest/coverage-v8": "^4.1.10",
39
46
  "@vitest/ui": "^4.1.10",
40
47
  "happy-dom": "^20.11.1",