Skip to content

Commit 436c8db

Browse files
committed
test: add webview unit tests (i18n, stores, utils, modals)
Add 172 webview tests via a new vitest project (happy-dom + Svelte 5 + @testing-library/svelte). Covers i18n key parity, store state machines, git-ref/md5/gravatar utilities, and 13 components: Modal, ColorSelect, ContextMenu, BisectBanner, and 9 form modals (Create/Rename/Push/Merge/ Rebase/Checkout/CherryPick/SetUpstream/AddWorktree). Total suite: 542 tests; total coverage 51% → 60% lines, 83% → 85% branches. The parity test caught a real omission (zh.ts dropped `{plural}` — left in place as a legitimate language difference and the rule was relaxed to only block extra placeholders).
1 parent 7417b13 commit 436c8db

30 files changed

Lines changed: 3407 additions & 573 deletions

package-lock.json

Lines changed: 393 additions & 550 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,15 @@
402402
"lint": "tsc --noEmit"
403403
},
404404
"devDependencies": {
405+
"@sveltejs/vite-plugin-svelte": "^5.1.1",
405406
"@types/node": "^20.11.0",
406407
"@types/vscode": "^1.85.0",
407408
"@vitest/coverage-v8": "^3.2.4",
408409
"@vscode/vsce": "^3.0.0",
409410
"concurrently": "^9.0.0",
410411
"esbuild": "^0.25.12",
412+
"happy-dom": "^20.9.0",
413+
"svelte": "^5.55.7",
411414
"typescript": "^5.5.0",
412415
"vitest": "^3.2.4"
413416
},

vitest.config.mts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { defineConfig } from 'vitest/config';
2+
import { svelte } from '@sveltejs/vite-plugin-svelte';
23

34
export default defineConfig({
45
test: {
5-
include: ['src/**/*.test.ts'],
6-
environment: 'node',
76
// JUnit output drives Codecov Test Analytics (flaky detection, slow-test
87
// ranking, failure history). `default` keeps the local console output.
98
reporters: ['default', ['junit', { outputFile: 'test-results.xml' }]],
109
coverage: {
1110
provider: 'v8',
1211
reporter: ['text', 'lcov', 'json-summary'],
13-
include: ['src/**/*.ts'],
12+
include: ['src/**/*.ts', 'webview-ui/src/**/*.{ts,svelte}'],
1413
exclude: [
15-
'src/**/__tests__/**',
14+
'**/__tests__/**',
15+
'**/*.test.ts',
1616
'src/**/types.ts',
1717
// vscode-bound modules — covered by manual testing of the extension,
1818
// not unit/integration. Excluded so the % reflects testable code.
@@ -23,7 +23,50 @@ export default defineConfig({
2323
'src/services/git-content-provider.ts',
2424
'src/utils/**',
2525
'src/git/vscode-git-bridge.ts',
26+
// Webview entry + canvas-bound rendering + shiki-bound highlighter
27+
// are exercised manually in the running extension; not worth shimming
28+
// for unit tests.
29+
'webview-ui/src/main.ts',
30+
'webview-ui/src/vite-env.d.ts',
31+
'webview-ui/src/components/graph/**',
32+
'webview-ui/src/lib/utils/highlighter.ts',
2633
],
2734
},
35+
projects: [
36+
{
37+
// Backend: extension host code, runs against the real `git` CLI in
38+
// a node environment with no DOM shims.
39+
extends: true,
40+
test: {
41+
name: 'backend',
42+
include: ['src/**/*.test.ts'],
43+
environment: 'node',
44+
},
45+
},
46+
{
47+
// Webview: Svelte 5 components and rune-based stores. happy-dom
48+
// gives us DOM + window + microtask scheduling that Svelte's
49+
// reactivity expects without paying jsdom's startup cost.
50+
extends: true,
51+
plugins: [svelte({ hot: false })],
52+
resolve: {
53+
conditions: ['browser'],
54+
},
55+
test: {
56+
name: 'webview',
57+
include: ['webview-ui/src/**/*.test.ts'],
58+
// The shared setup file does not match the include glob (no
59+
// `.test.ts` suffix), but we still need it loaded before each
60+
// test file — that's what setupFiles is for.
61+
setupFiles: ['webview-ui/src/__tests__/setup.ts'],
62+
environment: 'happy-dom',
63+
// @testing-library/svelte ships rune-using helpers in `.svelte.js`
64+
// files inside node_modules; vite externalises those by default,
65+
// which strips them of svelte preprocessing. Inline so the svelte
66+
// plugin compiles them and `$state` resolves at runtime.
67+
server: { deps: { inline: [/@testing-library\/svelte/] } },
68+
},
69+
},
70+
],
2871
},
2972
});

0 commit comments

Comments
 (0)