@rexezuge/tooling 1.2.0 → 1.4.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 +66 -10
- package/dist/eslint-boundaries.d.ts +31 -7
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +1 -138
- package/dist/eslint-boundaries.js.map +7 -1
- package/dist/eslint-rules.js +1 -273
- package/dist/eslint-rules.js.map +7 -1
- package/dist/eslint.d.ts +12 -7
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +1 -189
- package/dist/eslint.js.map +7 -1
- package/dist/functions/pages-proxy.d.ts.map +1 -1
- package/dist/functions/pages-proxy.js +1 -131
- package/dist/functions/pages-proxy.js.map +7 -1
- package/dist/index.d.ts +20 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -28
- package/dist/index.js.map +7 -1
- package/dist/scripts/backup/d1-target.d.ts +15 -5
- package/dist/scripts/backup/d1-target.d.ts.map +1 -1
- package/dist/scripts/backup/d1-target.js +1 -31
- package/dist/scripts/backup/d1-target.js.map +7 -1
- package/dist/scripts/backup/destination-config.d.ts +24 -8
- package/dist/scripts/backup/destination-config.d.ts.map +1 -1
- package/dist/scripts/backup/destination-config.js +1 -57
- package/dist/scripts/backup/destination-config.js.map +7 -1
- package/dist/scripts/backup/encrypt-backup.js +2 -97
- package/dist/scripts/backup/encrypt-backup.js.map +7 -1
- package/dist/scripts/backup/naming.d.ts +3 -1
- package/dist/scripts/backup/naming.d.ts.map +1 -1
- package/dist/scripts/backup/naming.js +1 -58
- package/dist/scripts/backup/naming.js.map +7 -1
- package/dist/scripts/check-god-files.d.ts +40 -14
- package/dist/scripts/check-god-files.d.ts.map +1 -1
- package/dist/scripts/check-god-files.js +2 -271
- package/dist/scripts/check-god-files.js.map +7 -1
- package/dist/scripts/ensure-spa-shell-stub.js +1 -29
- package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
- package/dist/scripts/init-secrets.d.ts +0 -16
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +2 -239
- package/dist/scripts/init-secrets.js.map +7 -1
- package/dist/scripts/lib/cli-args.d.ts.map +1 -1
- package/dist/scripts/lib/cli-args.js +1 -116
- package/dist/scripts/lib/cli-args.js.map +7 -1
- package/dist/scripts/lib/github-actions.js +3 -38
- package/dist/scripts/lib/github-actions.js.map +7 -1
- package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
- package/dist/scripts/lib/wrangler-table.js +2 -99
- package/dist/scripts/lib/wrangler-table.js.map +7 -1
- package/dist/scripts/migrations-lock.js +1 -44
- package/dist/scripts/migrations-lock.js.map +7 -1
- package/dist/scripts/prepare-wrangler-config.js +1 -49
- package/dist/scripts/prepare-wrangler-config.js.map +7 -1
- package/dist/scripts/spa-shell.d.ts +12 -4
- package/dist/scripts/spa-shell.d.ts.map +1 -1
- package/dist/scripts/spa-shell.js +3 -160
- package/dist/scripts/spa-shell.js.map +7 -1
- package/dist/scripts/validate-locales.d.ts +13 -5
- package/dist/scripts/validate-locales.d.ts.map +1 -1
- package/dist/scripts/validate-locales.js +4 -350
- package/dist/scripts/validate-locales.js.map +7 -1
- package/dist/scripts/verify-migrations.d.ts +27 -9
- package/dist/scripts/verify-migrations.d.ts.map +1 -1
- package/dist/scripts/verify-migrations.js +2 -312
- package/dist/scripts/verify-migrations.js.map +7 -1
- package/dist/scripts/verify-spa-shell.js +1 -52
- package/dist/scripts/verify-spa-shell.js.map +7 -1
- package/dist/scripts/wrangler-config/cli.js +3 -51
- package/dist/scripts/wrangler-config/cli.js.map +7 -1
- package/dist/scripts/wrangler-config/patches.d.ts +10 -4
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +4 -141
- package/dist/scripts/wrangler-config/patches.js.map +7 -1
- package/dist/scripts/wrangler-config/resources.d.ts +19 -7
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/resources.js +1 -290
- package/dist/scripts/wrangler-config/resources.js.map +7 -1
- package/dist/scripts/wrangler-config/types.d.ts +24 -8
- package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/types.js +1 -49
- package/dist/scripts/wrangler-config/types.js.map +7 -1
- package/dist/test/integration-migrations.d.ts +29 -12
- package/dist/test/integration-migrations.d.ts.map +1 -1
- package/dist/test/integration-migrations.js +2 -171
- package/dist/test/integration-migrations.js.map +7 -1
- package/dist/test/mocks/cloudflare-workers.js +1 -90
- package/dist/test/mocks/cloudflare-workers.js.map +7 -1
- package/dist/vite.d.ts +5 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +3 -125
- package/dist/vite.js.map +7 -1
- package/dist/vitest-aliases.d.ts +90 -0
- package/dist/vitest-aliases.d.ts.map +1 -0
- package/dist/vitest-aliases.js +1 -0
- package/dist/vitest-aliases.js.map +7 -0
- package/dist/vitest-integration.d.ts +96 -0
- package/dist/vitest-integration.d.ts.map +1 -0
- package/dist/vitest-integration.js +1 -0
- package/dist/vitest-integration.js.map +7 -0
- package/dist/vitest-repo.d.ts +154 -0
- package/dist/vitest-repo.d.ts.map +1 -0
- package/dist/vitest-repo.js +1 -0
- package/dist/vitest-repo.js.map +7 -0
- package/dist/vitest-web.d.ts +76 -19
- package/dist/vitest-web.d.ts.map +1 -1
- package/dist/vitest-web.js +1 -72
- package/dist/vitest-web.js.map +7 -1
- package/dist/vitest.d.ts +70 -19
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +1 -128
- package/dist/vitest.js.map +7 -1
- package/package.json +9 -3
- package/src/eslint-boundaries.ts +112 -11
- package/src/eslint.test.ts +40 -9
- package/src/eslint.ts +14 -9
- package/src/functions/pages-proxy.test.ts +3 -3
- package/src/functions/pages-proxy.ts +4 -2
- package/src/index.ts +23 -14
- package/src/scripts/backup/backup-rules.test.ts +4 -4
- package/src/scripts/backup/d1-target.ts +16 -6
- package/src/scripts/backup/destination-config.ts +27 -9
- package/src/scripts/backup/encrypt-backup.ts +12 -10
- package/src/scripts/backup/naming.ts +3 -1
- package/src/scripts/check-god-files.test.ts +19 -19
- package/src/scripts/check-god-files.ts +62 -33
- package/src/scripts/ensure-spa-shell-stub.ts +1 -1
- package/src/scripts/init-secrets.ts +20 -10
- package/src/scripts/lib/cli-args.ts +6 -3
- package/src/scripts/lib/wrangler-table.ts +5 -3
- package/src/scripts/migrations-lock.ts +2 -2
- package/src/scripts/prepare-wrangler-config.ts +3 -3
- package/src/scripts/spa-shell.test.ts +18 -18
- package/src/scripts/spa-shell.ts +26 -14
- package/src/scripts/validate-locales.test.ts +18 -18
- package/src/scripts/validate-locales.ts +43 -25
- package/src/scripts/verify-migrations.test.ts +8 -8
- package/src/scripts/verify-migrations.ts +47 -24
- package/src/scripts/verify-spa-shell.ts +1 -1
- package/src/scripts/wrangler-config/patches.ts +13 -5
- package/src/scripts/wrangler-config/resources.ts +34 -18
- package/src/scripts/wrangler-config/types.ts +24 -8
- package/src/test/integration-migrations.test.ts +7 -7
- package/src/test/integration-migrations.ts +33 -14
- package/src/vite.test.ts +25 -14
- package/src/vite.ts +5 -5
- package/src/vitest-aliases.test.ts +53 -0
- package/src/vitest-aliases.ts +125 -0
- package/src/vitest-factories.test.ts +127 -0
- package/src/vitest-integration.ts +118 -0
- package/src/vitest-repo.ts +269 -0
- package/src/vitest-web.ts +110 -28
- package/src/vitest.ts +96 -47
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single-file `projects` composition: backend (`node`) plus SPA (DOM).
|
|
3
|
+
*
|
|
4
|
+
* Provenance: AWS-AccessBridge (split by `.ts`/`.tsx` extension),
|
|
5
|
+
* Mail-Meow (split by `test/web/**` directory, with per-project `setupFiles`
|
|
6
|
+
* and the React plugin on the web project), CalDAV-Bridge (split by directory
|
|
7
|
+
* with `happy-dom`). The two-file repos (Durable-DAV-Router, Mail-Otter) keep
|
|
8
|
+
* `defineUnitVitestConfig()` + `defineWebVitestConfig()`; this factory is the
|
|
9
|
+
* same two halves as `projects` entries in one file, sharing one root coverage
|
|
10
|
+
* gate.
|
|
11
|
+
*
|
|
12
|
+
* Canonical decisions (all three sources agree):
|
|
13
|
+
*
|
|
14
|
+
* 1. **Coverage lives at the root**, not per project: one floor for the whole
|
|
15
|
+
* unit suite. (Durable-DAV-Router's warning about a shared floor stands for
|
|
16
|
+
* the two-file split; within one file the three sources all gate once.)
|
|
17
|
+
* 2. **Each project repeats the alias table.** Vitest projects do not inherit
|
|
18
|
+
* the root `resolve` (Mail-Meow), so a suite resolving `@scope/*`
|
|
19
|
+
* differently from its sibling fails like a product bug. Both entries carry
|
|
20
|
+
* the full table — backend with `@/` → API, web with `@/` + `~/` → SPA.
|
|
21
|
+
* 3. **The web project keeps `pool: 'threads'`** and its DOM from
|
|
22
|
+
* `defineWebVitestConfig()`; the backend project keeps `environment:
|
|
23
|
+
* 'node'` and `server.deps.inline` from `defineUnitVitestConfig()`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { defineConfig, type Plugin } from 'vitest/config';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
29
|
+
import type { VitestAlias } from './vitest-aliases.ts';
|
|
30
|
+
import type { CoverageThresholds } from './vitest.ts';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The backend half of the `projects` pair.
|
|
34
|
+
*/
|
|
35
|
+
export interface RepoBackendOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Which suites to collect. Defaults to the whole unit suite minus SPA and
|
|
38
|
+
* integration shapes.
|
|
39
|
+
*/
|
|
40
|
+
readonly include?: readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Suite paths to skip, replacing the default.
|
|
43
|
+
*/
|
|
44
|
+
readonly exclude?: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* Setup files run before each backend test file.
|
|
47
|
+
*/
|
|
48
|
+
readonly setupFiles?: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* `node_modules` specifiers to inline through Vite. Defaults to `['dofs']`.
|
|
51
|
+
*/
|
|
52
|
+
readonly serverDepsInline?: readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* Extra resolver entries for the backend project only.
|
|
55
|
+
*/
|
|
56
|
+
readonly aliases?: readonly VitestAlias[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The SPA half of the `projects` pair.
|
|
61
|
+
*/
|
|
62
|
+
export interface RepoWebOptions {
|
|
63
|
+
/**
|
|
64
|
+
* The DOM implementation. `jsdom` is the family default; `happy-dom` is
|
|
65
|
+
* CalDAV-Bridge's.
|
|
66
|
+
*/
|
|
67
|
+
readonly environment?: 'jsdom' | 'happy-dom';
|
|
68
|
+
/**
|
|
69
|
+
* Which suites to collect. Defaults to every SPA shape the family uses.
|
|
70
|
+
*/
|
|
71
|
+
readonly include?: readonly string[];
|
|
72
|
+
/**
|
|
73
|
+
* Suite paths to skip, replacing the default.
|
|
74
|
+
*/
|
|
75
|
+
readonly exclude?: readonly string[];
|
|
76
|
+
/**
|
|
77
|
+
* Setup files run before each SPA test file.
|
|
78
|
+
*/
|
|
79
|
+
readonly setupFiles?: readonly string[];
|
|
80
|
+
/**
|
|
81
|
+
* Vite plugins the SPA needs (`react()` for JSX).
|
|
82
|
+
*/
|
|
83
|
+
readonly plugins?: readonly Plugin[];
|
|
84
|
+
/**
|
|
85
|
+
* Extra resolver entries for the web project only.
|
|
86
|
+
*/
|
|
87
|
+
readonly aliases?: readonly VitestAlias[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* What `defineRepoVitestConfig` accepts.
|
|
92
|
+
*/
|
|
93
|
+
export interface RepoVitestConfigOptions {
|
|
94
|
+
/**
|
|
95
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`.
|
|
96
|
+
*/
|
|
97
|
+
readonly scope: string;
|
|
98
|
+
/**
|
|
99
|
+
* Workspace package directory names. Defaults to the family superset.
|
|
100
|
+
*/
|
|
101
|
+
readonly packages?: readonly string[];
|
|
102
|
+
/**
|
|
103
|
+
* Which `cloudflare:*` mocks to alias. Defaults to workers/sockets/workflows.
|
|
104
|
+
*/
|
|
105
|
+
readonly mocks?: readonly string[];
|
|
106
|
+
/**
|
|
107
|
+
* The repo root, as a file URL.
|
|
108
|
+
*/
|
|
109
|
+
readonly root?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Extra resolver entries applied to *both* projects (e.g. the `hono`
|
|
112
|
+
* dedupe). Per-project extras go on `backend.aliases` / `web.aliases`.
|
|
113
|
+
*/
|
|
114
|
+
readonly aliases?: readonly VitestAlias[];
|
|
115
|
+
/**
|
|
116
|
+
* Resolver `noExternal` patterns, merged after {@link KIT_NO_EXTERNAL}.
|
|
117
|
+
*/
|
|
118
|
+
readonly noExternal?: readonly (string | RegExp)[];
|
|
119
|
+
/**
|
|
120
|
+
* The backend half. Omitted fields take the `defineUnitVitestConfig`
|
|
121
|
+
* defaults.
|
|
122
|
+
*/
|
|
123
|
+
readonly backend?: RepoBackendOptions;
|
|
124
|
+
/**
|
|
125
|
+
* The SPA half. Omitted fields take the `defineWebVitestConfig` defaults.
|
|
126
|
+
*/
|
|
127
|
+
readonly web?: RepoWebOptions;
|
|
128
|
+
/**
|
|
129
|
+
* Coverage `include` globs. Defaults to the worker, the SPA and every
|
|
130
|
+
* workspace package's `src`.
|
|
131
|
+
*/
|
|
132
|
+
readonly coverageInclude?: readonly string[];
|
|
133
|
+
/**
|
|
134
|
+
* Coverage `exclude` globs, merged with the canonical set.
|
|
135
|
+
*/
|
|
136
|
+
readonly coverageExclude?: readonly string[];
|
|
137
|
+
/**
|
|
138
|
+
* Coverage floors. Omitted by default; a repo that wants them sets them.
|
|
139
|
+
*/
|
|
140
|
+
readonly thresholds?: CoverageThresholds;
|
|
141
|
+
/**
|
|
142
|
+
* Where the coverage report is written.
|
|
143
|
+
*/
|
|
144
|
+
readonly reportsDirectory?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Backend suites excluded from the backend project: the SPA shapes live in the
|
|
149
|
+
* web project, and integration is its own config.
|
|
150
|
+
*/
|
|
151
|
+
const BACKEND_EXCLUDE: readonly string[] = [
|
|
152
|
+
'**/node_modules/**',
|
|
153
|
+
'**/dist/**',
|
|
154
|
+
'test/integration/**',
|
|
155
|
+
'test/web/**',
|
|
156
|
+
'test/**/web-*.test.{ts,tsx}',
|
|
157
|
+
'apps/web/**/*.test.{ts,tsx}',
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* SPA suite shapes collected by the web project.
|
|
162
|
+
*/
|
|
163
|
+
const WEB_INCLUDE: readonly string[] = ['test/web/**/*.test.{ts,tsx}', 'test/**/web-*.test.{ts,tsx}', 'apps/web/**/*.test.{ts,tsx}'];
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Coverage `exclude`: the union of the unit and web halves' canonical sets.
|
|
167
|
+
*/
|
|
168
|
+
const CANONICAL_COVERAGE_EXCLUDE: readonly string[] = [
|
|
169
|
+
'scripts/**',
|
|
170
|
+
'**/*.test.ts',
|
|
171
|
+
'**/*.test.tsx',
|
|
172
|
+
'**/*.d.ts',
|
|
173
|
+
'**/index.ts',
|
|
174
|
+
'**/types.d.ts',
|
|
175
|
+
'**/types.ts',
|
|
176
|
+
'**/model/**',
|
|
177
|
+
'**/generated/**',
|
|
178
|
+
'**/D1Types.ts',
|
|
179
|
+
'**/ServiceEnv.ts',
|
|
180
|
+
'**/env.d.ts',
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Build the single-file `projects` config.
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* // vitest.config.mts
|
|
188
|
+
* import { defineRepoVitestConfig } from '@rexezuge/tooling/vitest-repo';
|
|
189
|
+
* export default defineRepoVitestConfig({
|
|
190
|
+
* scope: '@myapp',
|
|
191
|
+
* web: { environment: 'happy-dom' },
|
|
192
|
+
* thresholds: { statements: 87, branches: 77, functions: 88, lines: 90 },
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export function defineRepoVitestConfig(options: RepoVitestConfigOptions): ReturnType<typeof defineConfig> {
|
|
197
|
+
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
198
|
+
const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
|
|
199
|
+
const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
|
|
200
|
+
const noExternal = [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])];
|
|
201
|
+
const backend = options.backend ?? {};
|
|
202
|
+
const web = options.web ?? {};
|
|
203
|
+
|
|
204
|
+
const backendAliases = [
|
|
205
|
+
...workspaceAliases({ scope: options.scope, root, packages, mocks }),
|
|
206
|
+
...(options.aliases ?? []),
|
|
207
|
+
...(backend.aliases ?? []),
|
|
208
|
+
];
|
|
209
|
+
// `@/` means the SPA in the web project (Mail-Otter's SPA source imports
|
|
210
|
+
// through it); the workspace table's `@/` → API entry is dropped and the
|
|
211
|
+
// SPA's own prepended. `~/` → SPA either way.
|
|
212
|
+
const webSrc = fileURLToPath(new URL('apps/web/src', root));
|
|
213
|
+
const webAliases: VitestAlias[] = [
|
|
214
|
+
{ find: /^@\//, replacement: `${webSrc}/` },
|
|
215
|
+
{ find: /^~\//, replacement: `${webSrc}/` },
|
|
216
|
+
// Drop the workspace table's `@/`/`~/` (RegExp) entries — the SPA's own
|
|
217
|
+
// prepended above win — and keep the `@scope/*` + `cloudflare:*` strings.
|
|
218
|
+
...workspaceAliases({ scope: options.scope, root, packages, mocks }).filter((alias) => typeof alias.find === 'string'),
|
|
219
|
+
...(options.aliases ?? []),
|
|
220
|
+
...(web.aliases ?? []),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
return defineConfig({
|
|
224
|
+
test: {
|
|
225
|
+
projects: [
|
|
226
|
+
{
|
|
227
|
+
resolve: { alias: backendAliases, noExternal },
|
|
228
|
+
test: {
|
|
229
|
+
name: 'backend',
|
|
230
|
+
globals: true,
|
|
231
|
+
environment: 'node',
|
|
232
|
+
include: [...(backend.include ?? ['test/**/*.test.{ts,tsx}'])],
|
|
233
|
+
exclude: [...(backend.exclude ?? BACKEND_EXCLUDE)],
|
|
234
|
+
...(backend.setupFiles !== undefined && { setupFiles: [...backend.setupFiles] }),
|
|
235
|
+
server: { deps: { inline: [...(backend.serverDepsInline ?? ['dofs'])] } },
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
...(web.plugins !== undefined && { plugins: [...web.plugins] }),
|
|
240
|
+
resolve: { alias: webAliases, noExternal },
|
|
241
|
+
test: {
|
|
242
|
+
name: 'web',
|
|
243
|
+
globals: true,
|
|
244
|
+
environment: web.environment ?? 'jsdom',
|
|
245
|
+
include: [...(web.include ?? WEB_INCLUDE)],
|
|
246
|
+
exclude: [...(web.exclude ?? ['**/node_modules/**', '**/dist/**', 'test/integration/**'])],
|
|
247
|
+
pool: 'threads',
|
|
248
|
+
...(web.setupFiles !== undefined && { setupFiles: [...web.setupFiles] }),
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
coverage: {
|
|
253
|
+
provider: 'v8',
|
|
254
|
+
reporter: ['text', 'lcov', 'html'],
|
|
255
|
+
reportsDirectory: options.reportsDirectory ?? './coverage',
|
|
256
|
+
include: [
|
|
257
|
+
...(options.coverageInclude ?? [
|
|
258
|
+
'apps/api/src/**/*.ts',
|
|
259
|
+
'apps/background/src/**/*.ts',
|
|
260
|
+
'apps/web/src/**/*.{ts,tsx}',
|
|
261
|
+
'packages/**/src/**/*.ts',
|
|
262
|
+
]),
|
|
263
|
+
],
|
|
264
|
+
exclude: [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])],
|
|
265
|
+
...(options.thresholds !== undefined && { thresholds: { ...options.thresholds } }),
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
}
|
package/src/vitest-web.ts
CHANGED
|
@@ -1,39 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The SPA's test and coverage gate.
|
|
3
3
|
*
|
|
4
|
-
* Provenance: converged from Durable-DAV-Router's
|
|
5
|
-
* `vitest.web.config.mts
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
4
|
+
* Provenance: converged from all nine repos' SPA suites — Durable-DAV-Router's
|
|
5
|
+
* and Mail-Otter's `vitest.web.config.mts` (the two repos that gave the frontend
|
|
6
|
+
* its own file), Mail-Meow's and CalDAV-Bridge's `projects` entries (the two
|
|
7
|
+
* that keep backend and SPA in one file), and AWS-AccessBridge's
|
|
8
|
+
* extension-split `dom` project. Durable-DAV-Router's file is the canonical
|
|
9
|
+
* shape — it is the one that records *why* the split exists; Mail-Otter's
|
|
10
|
+
* contributes the React plugin and the `apps/web/**` include; CalDAV-Bridge
|
|
11
|
+
* contributes `happy-dom` and the `test/web/**` directory convention;
|
|
12
|
+
* Mail-Meow contributes `setupFiles` and the note that projects do not inherit
|
|
13
|
+
* the root `resolve`.
|
|
9
14
|
*
|
|
10
15
|
* Canonical decisions:
|
|
11
16
|
*
|
|
12
|
-
* 1. **
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
17
|
+
* 1. **A DOM for every file here**, rather than a `@vitest-environment` pragma
|
|
18
|
+
* per file: these are the tests that need a DOM, and the pragma is one more
|
|
19
|
+
* place to forget. `jsdom` is the family default (seven repos);
|
|
20
|
+
* `happy-dom` is CalDAV-Bridge's, and is one option away.
|
|
16
21
|
* 2. **`pool: 'threads'`, bounded, rather than one forked worker per file.** Each
|
|
17
22
|
* jsdom document is a whole browser environment; a fork per file exhausts
|
|
18
23
|
* memory on a constrained machine, and when it does the run dies partway with
|
|
19
24
|
* a bare "Worker exited unexpectedly" and no test reports a failure — which
|
|
20
25
|
* reads as a flaky suite rather than as an out-of-memory kill.
|
|
21
|
-
* 3.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* 3. **`include` covers every shape the family uses** — the `test/web/**`
|
|
27
|
+
* directory convention, the root-suite `web-*` naming convention, and suites
|
|
28
|
+
* bundled under `apps/web` — and the same globs are what
|
|
29
|
+
* `defineUnitVitestConfig()` excludes, so a file is collected by exactly one
|
|
30
|
+
* config.
|
|
31
|
+
* 4. **Projects do not inherit the root `resolve`** (Mail-Meow): a
|
|
32
|
+
* single-file `projects` composition must repeat the alias table per
|
|
33
|
+
* project. `defineRepoVitestConfig()` does that; two-file repos get it from
|
|
34
|
+
* these factories directly.
|
|
35
|
+
* 5. **`@/` means the SPA here, not the API worker.** The unit config maps
|
|
36
|
+
* `@/` to `apps/api/src`; this config maps both `@/` (Mail-Otter's SPA
|
|
37
|
+
* source) and `~/` (Mail-Meow's and CalDAV-Bridge's SPA tests) to
|
|
38
|
+
* `apps/web/src`. Workspace `@scope/*` imports still resolve to the
|
|
39
|
+
* packages, so web tests reach shared logic the same way backend tests do.
|
|
27
40
|
*/
|
|
28
41
|
|
|
29
42
|
import { defineConfig, type Plugin } from 'vitest/config';
|
|
30
43
|
import { fileURLToPath } from 'node:url';
|
|
31
|
-
import
|
|
44
|
+
import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
45
|
+
import type { VitestAlias } from './vitest-aliases.ts';
|
|
46
|
+
import type { CoverageThresholds } from './vitest.ts';
|
|
32
47
|
|
|
33
48
|
/**
|
|
34
49
|
* What `defineWebVitestConfig` accepts.
|
|
35
50
|
*/
|
|
36
51
|
export interface WebVitestConfigOptions {
|
|
52
|
+
/**
|
|
53
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`. When supplied, `@scope/*`
|
|
54
|
+
* workspace aliases are generated so web tests reach shared logic; when
|
|
55
|
+
* omitted, only the `cloudflare:*`, `@/` and `~/` aliases apply.
|
|
56
|
+
*/
|
|
57
|
+
readonly scope?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Workspace package directory names. Defaults to the family superset.
|
|
60
|
+
*/
|
|
61
|
+
readonly packages?: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* Which `cloudflare:*` mocks to alias. Defaults to workers/sockets/workflows.
|
|
64
|
+
*/
|
|
65
|
+
readonly mocks?: readonly string[];
|
|
37
66
|
/**
|
|
38
67
|
* Vite plugins the SPA needs — `@vitejs/plugin-react` for a React app. Passed
|
|
39
68
|
* by the consumer rather than imported here, because the kit must stay
|
|
@@ -41,7 +70,7 @@ export interface WebVitestConfigOptions {
|
|
|
41
70
|
*/
|
|
42
71
|
readonly plugins?: readonly Plugin[];
|
|
43
72
|
/**
|
|
44
|
-
* Extra resolver entries.
|
|
73
|
+
* Extra resolver entries, applied after the canonical ones.
|
|
45
74
|
*/
|
|
46
75
|
readonly aliases?: readonly VitestAlias[];
|
|
47
76
|
/**
|
|
@@ -49,9 +78,38 @@ export interface WebVitestConfigOptions {
|
|
|
49
78
|
*/
|
|
50
79
|
readonly root?: string;
|
|
51
80
|
/**
|
|
52
|
-
*
|
|
81
|
+
* The DOM implementation. `jsdom` is the family default; `happy-dom` is
|
|
82
|
+
* CalDAV-Bridge's (lighter, and sufficient for its hook/service suites).
|
|
83
|
+
*/
|
|
84
|
+
readonly environment?: 'jsdom' | 'happy-dom';
|
|
85
|
+
/**
|
|
86
|
+
* Which suites to collect. Defaults to every shape the family uses.
|
|
53
87
|
*/
|
|
54
88
|
readonly include?: readonly string[];
|
|
89
|
+
/**
|
|
90
|
+
* Suite paths to skip, replacing the default.
|
|
91
|
+
*/
|
|
92
|
+
readonly exclude?: readonly string[];
|
|
93
|
+
/**
|
|
94
|
+
* Setup files run before each test file.
|
|
95
|
+
*/
|
|
96
|
+
readonly setupFiles?: readonly string[];
|
|
97
|
+
/**
|
|
98
|
+
* `node_modules` specifiers to inline through Vite rather than externalize.
|
|
99
|
+
*/
|
|
100
|
+
readonly serverDepsInline?: readonly string[];
|
|
101
|
+
/**
|
|
102
|
+
* Resolver `noExternal` patterns, merged after {@link KIT_NO_EXTERNAL}.
|
|
103
|
+
*/
|
|
104
|
+
readonly noExternal?: readonly (string | RegExp)[];
|
|
105
|
+
/**
|
|
106
|
+
* Coverage `include` globs. Defaults to the SPA source.
|
|
107
|
+
*/
|
|
108
|
+
readonly coverageInclude?: readonly string[];
|
|
109
|
+
/**
|
|
110
|
+
* Coverage `exclude` globs, merged with the canonical set.
|
|
111
|
+
*/
|
|
112
|
+
readonly coverageExclude?: readonly string[];
|
|
55
113
|
/**
|
|
56
114
|
* Coverage floors. Omitted by default; see `defineUnitVitestConfig`.
|
|
57
115
|
*/
|
|
@@ -64,10 +122,16 @@ export interface WebVitestConfigOptions {
|
|
|
64
122
|
}
|
|
65
123
|
|
|
66
124
|
/**
|
|
67
|
-
* The default suite globs: the
|
|
68
|
-
*
|
|
125
|
+
* The default suite globs: every shape the family uses — the `test/web/**`
|
|
126
|
+
* directory convention, the root-suite `web-*` convention, and the
|
|
127
|
+
* bundled-under-`apps/web` convention — so any layout works unchanged.
|
|
128
|
+
*/
|
|
129
|
+
const DEFAULT_INCLUDE: readonly string[] = ['test/web/**/*.test.{ts,tsx}', 'test/**/web-*.test.{ts,tsx}', 'apps/web/**/*.test.{ts,tsx}'];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Coverage `exclude` globs for the SPA half.
|
|
69
133
|
*/
|
|
70
|
-
const
|
|
134
|
+
const CANONICAL_COVERAGE_EXCLUDE: readonly string[] = ['**/*.test.{ts,tsx}', '**/*.d.ts', '**/types.ts', '**/generated/**'];
|
|
71
135
|
|
|
72
136
|
/**
|
|
73
137
|
* Build the SPA's test config.
|
|
@@ -76,32 +140,50 @@ const DEFAULT_INCLUDE: readonly string[] = ['test/**/web-*.test.{ts,tsx}', 'apps
|
|
|
76
140
|
* // vitest.web.config.mts
|
|
77
141
|
* import react from '@vitejs/plugin-react';
|
|
78
142
|
* import { defineWebVitestConfig } from '@rexezuge/tooling/vitest-web';
|
|
79
|
-
* export default defineWebVitestConfig({ plugins: [react()] });
|
|
143
|
+
* export default defineWebVitestConfig({ scope: '@myapp', plugins: [react()] });
|
|
80
144
|
* ```
|
|
81
145
|
*/
|
|
82
146
|
export function defineWebVitestConfig(options: WebVitestConfigOptions = {}): ReturnType<typeof defineConfig> {
|
|
83
147
|
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
84
148
|
const webSrc = fileURLToPath(new URL('apps/web/src', root));
|
|
85
|
-
|
|
149
|
+
// The workspace table maps `@/` to the API worker; here `@/` means the SPA,
|
|
150
|
+
// so drop its `@/`/`~/` entries and prepend the SPA's own. String finds
|
|
151
|
+
// (`@scope/*`, `cloudflare:*`) survive; a placeholder scope contributes none.
|
|
152
|
+
const scopePart = workspaceAliases({
|
|
153
|
+
scope: options.scope ?? '@unused',
|
|
154
|
+
root,
|
|
155
|
+
packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES,
|
|
156
|
+
mocks: options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS,
|
|
157
|
+
}).filter((alias) => typeof alias.find === 'string' && !alias.find.startsWith('@unused'));
|
|
158
|
+
const aliases: VitestAlias[] = [
|
|
159
|
+
{ find: /^@\//, replacement: `${webSrc}/` },
|
|
160
|
+
{ find: /^~\//, replacement: `${webSrc}/` },
|
|
161
|
+
...scopePart.filter((alias) => typeof alias.find === 'string' && (alias.find.startsWith('cloudflare:') || options.scope !== undefined)),
|
|
162
|
+
...(options.aliases ?? []),
|
|
163
|
+
];
|
|
86
164
|
|
|
87
165
|
return defineConfig({
|
|
88
166
|
...(options.plugins !== undefined && { plugins: [...options.plugins] }),
|
|
89
|
-
resolve: { alias: aliases },
|
|
167
|
+
resolve: { alias: aliases, noExternal: [...KIT_NO_EXTERNAL, ...(options.noExternal ?? [])] },
|
|
90
168
|
test: {
|
|
91
169
|
globals: true,
|
|
92
|
-
environment: 'jsdom',
|
|
170
|
+
environment: options.environment ?? 'jsdom',
|
|
93
171
|
include: [...(options.include ?? DEFAULT_INCLUDE)],
|
|
94
172
|
// Threads, bounded, rather than one forked worker per file — see the
|
|
95
173
|
// header. A custom `exclude` replaces Vitest's defaults, so `node_modules`
|
|
96
174
|
// must be re-listed.
|
|
97
175
|
pool: 'threads',
|
|
98
|
-
exclude: ['**/node_modules/**', '**/dist/**', 'test/integration/**'],
|
|
176
|
+
exclude: [...(options.exclude ?? ['**/node_modules/**', '**/dist/**', 'test/integration/**'])],
|
|
177
|
+
...(options.setupFiles !== undefined && { setupFiles: [...options.setupFiles] }),
|
|
178
|
+
...(options.serverDepsInline !== undefined && {
|
|
179
|
+
server: { deps: { inline: [...options.serverDepsInline] } },
|
|
180
|
+
}),
|
|
99
181
|
coverage: {
|
|
100
182
|
provider: 'v8',
|
|
101
183
|
reporter: ['text', 'lcov'],
|
|
102
184
|
reportsDirectory: options.reportsDirectory ?? './coverage-spa',
|
|
103
|
-
include: ['apps/web/src/**/*.{ts,tsx}'],
|
|
104
|
-
exclude: [
|
|
185
|
+
include: [...(options.coverageInclude ?? ['apps/web/src/**/*.{ts,tsx}'])],
|
|
186
|
+
exclude: [...CANONICAL_COVERAGE_EXCLUDE, ...(options.coverageExclude ?? [])],
|
|
105
187
|
...(options.thresholds !== undefined && { thresholds: { ...options.thresholds } }),
|
|
106
188
|
},
|
|
107
189
|
},
|