@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
package/src/vite.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
|
-
import
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import { afterAll, describe, expect, it } from 'vitest';
|
|
5
|
-
import { defineWebViteConfig, spaShellEmbedPlugin } from './vite';
|
|
5
|
+
import { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';
|
|
6
6
|
|
|
7
7
|
const created: string[] = [];
|
|
8
8
|
|
|
9
9
|
function tempRoot(): string {
|
|
10
|
-
const root = mkdtempSync(join(tmpdir(), 'vite-config-'));
|
|
10
|
+
const root = mkdtempSync(path.join(tmpdir(), 'vite-config-'));
|
|
11
11
|
created.push(root);
|
|
12
12
|
return root;
|
|
13
13
|
}
|
|
@@ -18,11 +18,22 @@ afterAll(() => {
|
|
|
18
18
|
|
|
19
19
|
const REAL_HTML = `<!doctype html><html><head><meta charset="utf-8" /><title>Fixture</title><script type="module" src="/assets/index-abc123.js"></script></head><body><div id="root"></div><!-- padding so the shell is a real document --></body></html>`;
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
Names of the object-form plugins, skipping the falsy entries a config may hold.
|
|
23
|
+
*/
|
|
24
|
+
function pluginNames(plugins: readonly unknown[] | undefined): string[] {
|
|
25
|
+
return (plugins ?? []).flatMap((plugin) =>
|
|
26
|
+
typeof plugin === 'object' && plugin !== null && 'name' in plugin ? [String(plugin.name)] : [],
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
A build output: `dist/index.html` plus the bundle it references.
|
|
32
|
+
*/
|
|
22
33
|
function writeBuild(root: string): void {
|
|
23
|
-
mkdirSync(join(root, 'dist', 'assets'), { recursive: true });
|
|
24
|
-
writeFileSync(join(root, 'dist', 'index.html'), REAL_HTML, 'utf8');
|
|
25
|
-
writeFileSync(join(root, 'dist', 'assets', 'index-abc123.js'), 'console.log(1)', 'utf8');
|
|
34
|
+
mkdirSync(path.join(root, 'dist', 'assets'), { recursive: true });
|
|
35
|
+
writeFileSync(path.join(root, 'dist', 'index.html'), REAL_HTML, 'utf8');
|
|
36
|
+
writeFileSync(path.join(root, 'dist', 'assets', 'index-abc123.js'), 'console.log(1)', 'utf8');
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
describe('defineWebViteConfig', () => {
|
|
@@ -40,8 +51,8 @@ describe('defineWebViteConfig', () => {
|
|
|
40
51
|
it('registers the spa-shell plugin only when a target is given', () => {
|
|
41
52
|
const withShell = defineWebViteConfig({ plugins: [], spaShell: { path: 'apps/api/src/generated/spa-shell.ts' } });
|
|
42
53
|
const without = defineWebViteConfig({ plugins: [] });
|
|
43
|
-
expect(withShell.plugins
|
|
44
|
-
expect(without.plugins
|
|
54
|
+
expect(pluginNames(withShell.plugins)).toContain('spa-shell-embed');
|
|
55
|
+
expect(pluginNames(without.plugins)).toStrictEqual([]);
|
|
45
56
|
});
|
|
46
57
|
});
|
|
47
58
|
|
|
@@ -53,7 +64,7 @@ describe('spaShellEmbedPlugin', () => {
|
|
|
53
64
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
54
65
|
await plugin.closeBundle?.();
|
|
55
66
|
|
|
56
|
-
const written = readFileSync(join(root, 'apps/api/src/generated/spa-shell.ts'), 'utf8');
|
|
67
|
+
const written = readFileSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'), 'utf8');
|
|
57
68
|
expect(written).toContain('export const SPA_HTML: string = ');
|
|
58
69
|
expect(written).toContain('DO NOT EDIT');
|
|
59
70
|
// A verbatim copy: verify-spa-shell compares the two byte for byte.
|
|
@@ -65,19 +76,19 @@ describe('spaShellEmbedPlugin', () => {
|
|
|
65
76
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
66
77
|
// closeBundle runs on every build, including library builds with no HTML.
|
|
67
78
|
expect(() => plugin.closeBundle?.()).not.toThrow();
|
|
68
|
-
expect(existsSync(join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
79
|
+
expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
69
80
|
});
|
|
70
81
|
|
|
71
82
|
it('resolves against the build directory, never against this module', async () => {
|
|
72
83
|
const root = tempRoot();
|
|
73
84
|
writeBuild(root);
|
|
74
|
-
mkdirSync(dirname(join(root, 'apps/api/src/generated')), { recursive: true });
|
|
85
|
+
mkdirSync(path.dirname(path.join(root, 'apps/api/src/generated')), { recursive: true });
|
|
75
86
|
|
|
76
87
|
const plugin = spaShellEmbedPlugin({ path: 'apps/api/src/generated/spa-shell.ts', root });
|
|
77
88
|
await plugin.closeBundle?.();
|
|
78
89
|
|
|
79
|
-
expect(existsSync(join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
|
|
90
|
+
expect(existsSync(path.join(root, 'apps/api/src/generated/spa-shell.ts'))).toBe(true);
|
|
80
91
|
// The kit's own directory must not gain a generated file from a consumer's build.
|
|
81
|
-
expect(existsSync(join(process.cwd(), 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
92
|
+
expect(existsSync(path.join(process.cwd(), 'apps/api/src/generated/spa-shell.ts'))).toBe(false);
|
|
82
93
|
});
|
|
83
94
|
});
|
package/src/vite.ts
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
33
|
-
import
|
|
33
|
+
import path from 'node:path';
|
|
34
34
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
35
|
-
import { defineConfig, type Plugin } from 'vitest/config';
|
|
35
|
+
import { defineConfig, type Plugin, type ViteUserConfig } from 'vitest/config';
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* One dev-server proxy entry, as Vite's `server.proxy` accepts it.
|
|
@@ -143,7 +143,7 @@ function toDirUrl(value: string | URL): URL {
|
|
|
143
143
|
return url.href.endsWith('/') ? url : new URL(`${url.href}/`);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
export function spaShellEmbedPlugin(target: SpaShellTarget): Plugin {
|
|
146
|
+
export function spaShellEmbedPlugin(target: SpaShellTarget): Plugin & { closeBundle: () => void } {
|
|
147
147
|
return {
|
|
148
148
|
name: 'spa-shell-embed',
|
|
149
149
|
closeBundle() {
|
|
@@ -165,7 +165,7 @@ export function spaShellEmbedPlugin(target: SpaShellTarget): Plugin {
|
|
|
165
165
|
const html = readFileSync(indexPath, 'utf8');
|
|
166
166
|
const output = `// Auto-generated by Vite build plugin - DO NOT EDIT.\nexport const SPA_HTML: string = ${JSON.stringify(html)};\n`;
|
|
167
167
|
|
|
168
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
168
|
+
mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
169
169
|
writeFileSync(outputPath, output);
|
|
170
170
|
},
|
|
171
171
|
};
|
|
@@ -186,7 +186,7 @@ export function spaShellEmbedPlugin(target: SpaShellTarget): Plugin {
|
|
|
186
186
|
* });
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
|
-
export function defineWebViteConfig(options: WebViteConfigOptions = {}):
|
|
189
|
+
export function defineWebViteConfig(options: WebViteConfigOptions = {}): ViteUserConfig {
|
|
190
190
|
const plugins: Plugin[] = [...(options.plugins ?? [])];
|
|
191
191
|
if (options.spaShell !== undefined) {
|
|
192
192
|
plugins.push(spaShellEmbedPlugin(options.spaShell));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
3
|
+
|
|
4
|
+
const ROOT = new URL('.', import.meta.url).href;
|
|
5
|
+
|
|
6
|
+
function finds(aliases: ReturnType<typeof workspaceAliases>): string[] {
|
|
7
|
+
return aliases.map((alias) => String(alias.find));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('workspaceAliases', () => {
|
|
11
|
+
it('generates one alias per workspace package under the caller scope', () => {
|
|
12
|
+
const aliases = workspaceAliases({ scope: '@fixture', root: ROOT });
|
|
13
|
+
for (const name of ['shared', 'backend-data', 'backend-services', 'provider-clients', 'webdav', 'background']) {
|
|
14
|
+
expect(finds(aliases)).toContain(`@fixture/${name}`);
|
|
15
|
+
}
|
|
16
|
+
// Another repo's scope never leaks in.
|
|
17
|
+
expect(finds(aliases).some((find) => find.startsWith('@durable-dav/'))).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('resolves background under apps/ and packages under packages/', () => {
|
|
21
|
+
const aliases = workspaceAliases({ scope: '@fixture', root: ROOT });
|
|
22
|
+
const byFind = new Map(aliases.map((alias) => [String(alias.find), alias.replacement]));
|
|
23
|
+
expect(byFind.get('@fixture/background')).toContain('apps/background/src');
|
|
24
|
+
expect(byFind.get('@fixture/shared')).toContain('packages/shared/src');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('aliases the cloudflare runtime mocks plus the @/ and ~/ prefixes', () => {
|
|
28
|
+
const aliases = workspaceAliases({ scope: '@fixture', root: ROOT });
|
|
29
|
+
expect(finds(aliases)).toContain('cloudflare:workers');
|
|
30
|
+
expect(aliases.some((alias) => alias.find instanceof RegExp && alias.find.source === String.raw`^@\/`)).toBe(true);
|
|
31
|
+
expect(aliases.some((alias) => alias.find instanceof RegExp && alias.find.source === String.raw`^~\/`)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('lets a repo narrow the package and mock sets', () => {
|
|
35
|
+
const aliases = workspaceAliases({ scope: '@fixture', root: ROOT, packages: ['shared'], mocks: ['workers'] });
|
|
36
|
+
expect(finds(aliases)).toContain('@fixture/shared');
|
|
37
|
+
expect(finds(aliases)).not.toContain('@fixture/webdav');
|
|
38
|
+
expect(finds(aliases)).toContain('cloudflare:workers');
|
|
39
|
+
expect(finds(aliases)).not.toContain('cloudflare:sockets');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('defaults to the family superset of packages and mocks', () => {
|
|
43
|
+
expect(DEFAULT_WORKSPACE_PACKAGES).toContain('provider-clients');
|
|
44
|
+
expect(DEFAULT_WORKSPACE_PACKAGES).toContain('webdav');
|
|
45
|
+
expect(DEFAULT_WORKSPACE_PACKAGES).toContain('git-protocol');
|
|
46
|
+
expect(DEFAULT_CLOUDFLARE_MOCKS).toEqual(['workers', 'sockets', 'workflows']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('keeps the kit inside Vite via KIT_NO_EXTERNAL', () => {
|
|
50
|
+
expect(KIT_NO_EXTERNAL.some((pattern) => pattern.test('@rexezuge/d1'))).toBe(true);
|
|
51
|
+
expect(KIT_NO_EXTERNAL.some((pattern) => pattern.test('vitest'))).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One `{ find, replacement }` pair for Vitest's resolver.
|
|
5
|
+
*
|
|
6
|
+
* A `string` find is a prefix match in Vite; a `RegExp` find is tested against
|
|
7
|
+
* the specifier. Workspace scopes use plain strings (`'@scope/name'` matches
|
|
8
|
+
* `'@scope/name'` and `'@scope/name/sub'` alike); `@/` and `~/` use regexps so
|
|
9
|
+
* the trailing slash is part of the match.
|
|
10
|
+
*/
|
|
11
|
+
export interface VitestAlias {
|
|
12
|
+
readonly find: string | RegExp;
|
|
13
|
+
readonly replacement: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Every workspace package the family has converged on, as directory names under
|
|
18
|
+
* `packages/`.
|
|
19
|
+
*
|
|
20
|
+
* The union across all nine repos: the universal core (`shared`,
|
|
21
|
+
* `backend-errors`, `backend-runtime`, `backend-data`, `backend-services`) plus
|
|
22
|
+
* the domain packages (`provider-clients`, `webdav`, `dav-store`,
|
|
23
|
+
* `git-protocol`, `git-service`). `media-tags`/`subsonic` (Edge-Sonic) are
|
|
24
|
+
* unconstrained utility leaves with no boundary block and no alias in their
|
|
25
|
+
* source repo, so they are not listed — a repo that needs them passes
|
|
26
|
+
* `packages` explicitly or appends `aliases`.
|
|
27
|
+
*
|
|
28
|
+
* A superset is safe: an alias for a package the consumer does not have never
|
|
29
|
+
* matches a specifier, and Vite only resolves the replacement when something
|
|
30
|
+
* imports it.
|
|
31
|
+
*/
|
|
32
|
+
export const DEFAULT_WORKSPACE_PACKAGES: readonly string[] = [
|
|
33
|
+
'shared',
|
|
34
|
+
'backend-errors',
|
|
35
|
+
'backend-runtime',
|
|
36
|
+
'backend-data',
|
|
37
|
+
'provider-clients',
|
|
38
|
+
'webdav',
|
|
39
|
+
'dav-store',
|
|
40
|
+
'git-protocol',
|
|
41
|
+
'git-service',
|
|
42
|
+
'backend-services',
|
|
43
|
+
'background',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The Cloudflare runtime mocks the unit suite aliases.
|
|
48
|
+
*
|
|
49
|
+
* `workers` exists in every repo; `sockets` in five; `workflows` in four. All
|
|
50
|
+
* three are listed by default: an alias whose mock file is absent never fires
|
|
51
|
+
* unless a test imports the specifier, and then the missing file is the correct
|
|
52
|
+
* error rather than Node's `ERR_UNKNOWN_SCHEME` for `cloudflare:*`.
|
|
53
|
+
*/
|
|
54
|
+
export const DEFAULT_CLOUDFLARE_MOCKS: readonly string[] = ['workers', 'sockets', 'workflows'];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Keep the kit's own `dist/` inside Vite's pipeline.
|
|
58
|
+
*
|
|
59
|
+
* The kit ships ESM `dist/` with bundler-style extensionless relative imports
|
|
60
|
+
* (its tsconfig is `moduleResolution: Bundler`), which Node's ESM resolver
|
|
61
|
+
* refuses. Vitest externalizes `node_modules` deps by default and would import
|
|
62
|
+
* that dist with Node; `noExternal` routes `@rexezuge/*` back through Vite —
|
|
63
|
+
* the same resolver that bundles the worker — so a test loads the very dist
|
|
64
|
+
* the worker ships. Without this, the run dies on `./BaseDAO` inside
|
|
65
|
+
* `@rexezuge/d1`'s `dist/index.js`.
|
|
66
|
+
*/
|
|
67
|
+
export const KIT_NO_EXTERNAL: readonly RegExp[] = [/(^|[/\\])@rexezuge\//];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* What `workspaceAliases` accepts.
|
|
71
|
+
*/
|
|
72
|
+
export interface WorkspaceAliasesOptions {
|
|
73
|
+
/**
|
|
74
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`. Every `@scope/*` alias is
|
|
75
|
+
* derived from it, so the same factory serves all nine repos.
|
|
76
|
+
*/
|
|
77
|
+
readonly scope: string;
|
|
78
|
+
/**
|
|
79
|
+
* The repo root, as a file URL. Pass `new URL('.', import.meta.url).href`
|
|
80
|
+
* from the calling config — never `import.meta.url` of this module, which
|
|
81
|
+
* points inside `node_modules/@rexezuge/tooling`.
|
|
82
|
+
*/
|
|
83
|
+
readonly root: string;
|
|
84
|
+
/**
|
|
85
|
+
* Workspace package directory names under `packages/` plus `background`
|
|
86
|
+
* (which lives under `apps/`). Defaults to {@link DEFAULT_WORKSPACE_PACKAGES}.
|
|
87
|
+
*/
|
|
88
|
+
readonly packages?: readonly string[];
|
|
89
|
+
/**
|
|
90
|
+
* Which `cloudflare:*` mocks to alias. Defaults to {@link DEFAULT_CLOUDFLARE_MOCKS}.
|
|
91
|
+
*/
|
|
92
|
+
readonly mocks?: readonly string[];
|
|
93
|
+
/**
|
|
94
|
+
* Extra resolver entries, applied after the canonical ones.
|
|
95
|
+
*/
|
|
96
|
+
readonly extraAliases?: readonly VitestAlias[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Build the workspace alias table for a consumer repo.
|
|
101
|
+
*
|
|
102
|
+
* Aliases point at source rather than at built output, so a test exercises the
|
|
103
|
+
* code the worker would run without a build step. `background` resolves under
|
|
104
|
+
* `apps/`; every other package under `packages/`. `@/` maps to the API worker
|
|
105
|
+
* source and `~/` to the SPA source, matching the two `tsconfig` path prefixes
|
|
106
|
+
* every repo shares.
|
|
107
|
+
*/
|
|
108
|
+
export function workspaceAliases(options: WorkspaceAliasesOptions): VitestAlias[] {
|
|
109
|
+
const { scope, root } = options;
|
|
110
|
+
const packages = options.packages ?? DEFAULT_WORKSPACE_PACKAGES;
|
|
111
|
+
const mocks = options.mocks ?? DEFAULT_CLOUDFLARE_MOCKS;
|
|
112
|
+
const at = (relative: string): string => fileURLToPath(new URL(relative, root));
|
|
113
|
+
const aliases: VitestAlias[] = [];
|
|
114
|
+
for (const name of packages) {
|
|
115
|
+
const dir = name === 'background' ? 'apps/background/src' : `packages/${name}/src`;
|
|
116
|
+
aliases.push({ find: `${scope}/${name}`, replacement: at(dir) });
|
|
117
|
+
}
|
|
118
|
+
for (const mock of mocks) {
|
|
119
|
+
aliases.push({ find: `cloudflare:${mock}`, replacement: at(`test/mocks/cloudflare-${mock}.ts`) });
|
|
120
|
+
}
|
|
121
|
+
const apiSrc = at('apps/api/src');
|
|
122
|
+
const webSrc = at('apps/web/src');
|
|
123
|
+
aliases.push({ find: /^@\//, replacement: `${apiSrc}/` }, { find: /^~\//, replacement: `${webSrc}/` }, ...(options.extraAliases ?? []));
|
|
124
|
+
return aliases;
|
|
125
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { defineUnitVitestConfig } from './vitest.ts';
|
|
3
|
+
import { defineWebVitestConfig } from './vitest-web.ts';
|
|
4
|
+
import { defineRepoVitestConfig } from './vitest-repo.ts';
|
|
5
|
+
import { defineIntegrationVitestConfig } from './vitest-integration.ts';
|
|
6
|
+
|
|
7
|
+
const ROOT = new URL('.', import.meta.url).href;
|
|
8
|
+
|
|
9
|
+
function aliasesOf(config: unknown): Array<{ find: unknown; replacement: string }> {
|
|
10
|
+
const resolve = (config as { resolve?: { alias?: Array<{ find: unknown; replacement: string }> } }).resolve;
|
|
11
|
+
return resolve?.alias ?? [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function testOf(config: unknown): Record<string, unknown> {
|
|
15
|
+
return (config as { test?: Record<string, unknown> }).test ?? {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('defineUnitVitestConfig', () => {
|
|
19
|
+
it('generates the workspace table from scope', () => {
|
|
20
|
+
const aliases = aliasesOf(defineUnitVitestConfig({ scope: '@fixture', root: ROOT }));
|
|
21
|
+
const finds = aliases.map((alias) => String(alias.find));
|
|
22
|
+
expect(finds).toContain('@fixture/backend-services');
|
|
23
|
+
expect(finds).toContain('@fixture/provider-clients');
|
|
24
|
+
expect(finds).toContain('cloudflare:workers');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('keeps @rexezuge/* inside Vite by default and merges consumer patterns', () => {
|
|
28
|
+
const config = defineUnitVitestConfig({ scope: '@fixture', root: ROOT, noExternal: [/custom-pkg/] });
|
|
29
|
+
const noExternal = (config as { resolve?: { noExternal?: unknown[] } }).resolve?.noExternal ?? [];
|
|
30
|
+
expect(noExternal.some((pattern) => pattern instanceof RegExp && pattern.test('@rexezuge/d1'))).toBe(true);
|
|
31
|
+
expect(noExternal.some((pattern) => pattern instanceof RegExp && pattern.test('custom-pkg'))).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('excludes every SPA shape the family uses', () => {
|
|
35
|
+
const exclude = (testOf(defineUnitVitestConfig({ root: ROOT }))['exclude'] as string[]) ?? [];
|
|
36
|
+
expect(exclude).toContain('test/web/**');
|
|
37
|
+
expect(exclude).toContain('test/**/web-*.test.{ts,tsx}');
|
|
38
|
+
expect(exclude).toContain('apps/web/**/*.test.{ts,tsx}');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('accepts include/setupFiles/serverDepsInline overrides', () => {
|
|
42
|
+
const test = testOf(
|
|
43
|
+
defineUnitVitestConfig({ root: ROOT, include: ['test/a/**/*.test.ts'], setupFiles: ['test/setup.ts'], serverDepsInline: [] }),
|
|
44
|
+
);
|
|
45
|
+
expect(test['include']).toEqual(['test/a/**/*.test.ts']);
|
|
46
|
+
expect(test['setupFiles']).toEqual(['test/setup.ts']);
|
|
47
|
+
expect(test['server']).toEqual({ deps: { inline: [] } });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('defineWebVitestConfig', () => {
|
|
52
|
+
it('maps @/ and ~/ to the SPA source, not the API worker', () => {
|
|
53
|
+
const aliases = aliasesOf(defineWebVitestConfig({ scope: '@fixture', root: ROOT }));
|
|
54
|
+
const at = aliases.find((alias) => alias.find instanceof RegExp && alias.find.source === String.raw`^@\/`);
|
|
55
|
+
const tilde = aliases.find((alias) => alias.find instanceof RegExp && alias.find.source === String.raw`^~\/`);
|
|
56
|
+
expect(at?.replacement).toContain('apps/web/src');
|
|
57
|
+
expect(tilde?.replacement).toContain('apps/web/src');
|
|
58
|
+
// The workspace scope table still resolves beside them.
|
|
59
|
+
expect(aliases.map((alias) => String(alias.find))).toContain('@fixture/shared');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('defaults to jsdom and accepts happy-dom', () => {
|
|
63
|
+
expect(testOf(defineWebVitestConfig({ root: ROOT }))['environment']).toBe('jsdom');
|
|
64
|
+
expect(testOf(defineWebVitestConfig({ root: ROOT, environment: 'happy-dom' }))['environment']).toBe('happy-dom');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('collects every SPA shape the family uses', () => {
|
|
68
|
+
const include = (testOf(defineWebVitestConfig({ root: ROOT }))['include'] as string[]) ?? [];
|
|
69
|
+
expect(include).toContain('test/web/**/*.test.{ts,tsx}');
|
|
70
|
+
expect(include).toContain('test/**/web-*.test.{ts,tsx}');
|
|
71
|
+
expect(include).toContain('apps/web/**/*.test.{ts,tsx}');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('defineRepoVitestConfig', () => {
|
|
76
|
+
it('composes backend/node and web/DOM projects with per-project aliases', () => {
|
|
77
|
+
const projects =
|
|
78
|
+
(testOf(defineRepoVitestConfig({ scope: '@fixture', root: ROOT }))['projects'] as Array<Record<string, unknown>>) ?? [];
|
|
79
|
+
expect(projects).toHaveLength(2);
|
|
80
|
+
const backend = projects[0]?.['test'] as Record<string, unknown>;
|
|
81
|
+
const web = projects[1]?.['test'] as Record<string, unknown>;
|
|
82
|
+
expect(backend?.['name']).toBe('backend');
|
|
83
|
+
expect(backend?.['environment']).toBe('node');
|
|
84
|
+
expect(web?.['name']).toBe('web');
|
|
85
|
+
expect(web?.['environment']).toBe('jsdom');
|
|
86
|
+
// Projects do not inherit the root resolve, so each repeats the table.
|
|
87
|
+
for (const project of projects) {
|
|
88
|
+
const finds = ((project as { resolve?: { alias?: Array<{ find: unknown }> } }).resolve?.alias ?? []).map((alias) =>
|
|
89
|
+
String(alias.find),
|
|
90
|
+
);
|
|
91
|
+
expect(finds).toContain('@fixture/shared');
|
|
92
|
+
}
|
|
93
|
+
// And the web project's @/ is the SPA, not the API worker.
|
|
94
|
+
const webAt = ((projects[1] as { resolve?: { alias?: Array<{ find: unknown; replacement: string }> } }).resolve?.alias ?? []).find(
|
|
95
|
+
(alias) => alias.find instanceof RegExp && alias.find.source === String.raw`^@\/`,
|
|
96
|
+
);
|
|
97
|
+
expect(webAt?.replacement).toContain('apps/web/src');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('passes the DOM choice and coverage floor through', () => {
|
|
101
|
+
const config = defineRepoVitestConfig({
|
|
102
|
+
scope: '@fixture',
|
|
103
|
+
root: ROOT,
|
|
104
|
+
web: { environment: 'happy-dom' },
|
|
105
|
+
thresholds: { statements: 87 },
|
|
106
|
+
});
|
|
107
|
+
const projects = (testOf(config)['projects'] as Array<Record<string, unknown>>) ?? [];
|
|
108
|
+
expect((projects[1]?.['test'] as Record<string, unknown>)?.['environment']).toBe('happy-dom');
|
|
109
|
+
expect((testOf(config)['coverage'] as Record<string, unknown>)?.['thresholds']).toEqual({ statements: 87 });
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('defineIntegrationVitestConfig', () => {
|
|
114
|
+
it('aliases the workspace without cloudflare mocks and collects .int tests', () => {
|
|
115
|
+
const config = defineIntegrationVitestConfig({ scope: '@fixture', root: ROOT });
|
|
116
|
+
const finds = aliasesOf(config).map((alias) => String(alias.find));
|
|
117
|
+
expect(finds).toContain('@fixture/backend-data');
|
|
118
|
+
expect(finds.some((find) => find.startsWith('cloudflare:'))).toBe(false);
|
|
119
|
+
expect(testOf(config)['include']).toEqual(['test/integration/**/*.int.test.ts']);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('covers the sqlite shape with no harness wiring', () => {
|
|
123
|
+
const test = testOf(defineIntegrationVitestConfig({ scope: '@fixture', root: ROOT, include: ['test/integration/**/*.test.ts'] }));
|
|
124
|
+
expect(test['include']).toEqual(['test/integration/**/*.test.ts']);
|
|
125
|
+
expect(test['pool']).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The integration-suite Vitest config.
|
|
3
|
+
*
|
|
4
|
+
* Provenance: the eight `test/integration/vitest.config.mts` workerd suites
|
|
5
|
+
* plus CalDAV-Bridge's `node:sqlite` suite. Every one hand-writes the same
|
|
6
|
+
* `@scope/* → src` workspace table (8–20 entries) beside its own harness
|
|
7
|
+
* wiring; this factory generates that table from `scope` so the two cannot
|
|
8
|
+
* drift apart — a suite resolving a workspace import differently from the unit
|
|
9
|
+
* suite fails in a way that looks like a product bug.
|
|
10
|
+
*
|
|
11
|
+
* What the factory does not do, deliberately: the workerd suites' `plugins`
|
|
12
|
+
* (`@cloudflare/vitest-pool-workers`), `pool` and migration-SQL `define` are
|
|
13
|
+
* harness wiring that belongs to the repo, and importing the workerd plugin
|
|
14
|
+
* here would make the tooling package undownloadable for a consumer without
|
|
15
|
+
* it. The factory takes them as opaque pass-through and returns them
|
|
16
|
+
* untouched. CalDAV-Bridge's suite passes none of them (plain `node` +
|
|
17
|
+
* `node:sqlite`, no coverage); the workerd suites pass all three.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { defineConfig, type Plugin } from 'vitest/config';
|
|
21
|
+
import type { Pool } from 'vitest/node';
|
|
22
|
+
import { DEFAULT_WORKSPACE_PACKAGES, workspaceAliases } from './vitest-aliases.ts';
|
|
23
|
+
import type { VitestAlias } from './vitest-aliases.ts';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What `defineIntegrationVitestConfig` accepts.
|
|
27
|
+
*/
|
|
28
|
+
export interface IntegrationVitestConfigOptions {
|
|
29
|
+
/**
|
|
30
|
+
* The consuming repo's npm scope, e.g. `'@myapp'`.
|
|
31
|
+
*/
|
|
32
|
+
readonly scope: string;
|
|
33
|
+
/**
|
|
34
|
+
* Workspace package directory names. Defaults to the family superset.
|
|
35
|
+
*/
|
|
36
|
+
readonly packages?: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* The repo root, as a file URL.
|
|
39
|
+
*/
|
|
40
|
+
readonly root?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Extra resolver entries, applied after the workspace table (e.g. the
|
|
43
|
+
* `hono` dedupe two repos carry).
|
|
44
|
+
*/
|
|
45
|
+
readonly aliases?: readonly VitestAlias[];
|
|
46
|
+
/**
|
|
47
|
+
* Which suites to collect. Workerd suites use
|
|
48
|
+
* `test/integration/**/*.int.test.ts`; CalDAV-Bridge's sqlite suite uses
|
|
49
|
+
* `test/integration/**/*.test.ts`.
|
|
50
|
+
*/
|
|
51
|
+
readonly include?: readonly string[];
|
|
52
|
+
/**
|
|
53
|
+
* The Vitest plugins (the workerd `cloudflareTest()` plugin). Typed as the
|
|
54
|
+
* runner's own plugin so a workerd plugin is accepted and nothing new is
|
|
55
|
+
* imported — this package stays dependency-free.
|
|
56
|
+
*/
|
|
57
|
+
readonly plugins?: readonly Plugin[];
|
|
58
|
+
/**
|
|
59
|
+
* The pool (the workerd `cloudflarePool()`). The runner's own `Pool` type,
|
|
60
|
+
* so a custom pool is accepted without importing its provider.
|
|
61
|
+
*/
|
|
62
|
+
readonly pool?: Pool;
|
|
63
|
+
/**
|
|
64
|
+
* Compile-time defines (the migration SQL/SQLite bundle each suite injects).
|
|
65
|
+
* Opaque, passed through.
|
|
66
|
+
*/
|
|
67
|
+
readonly define?: Readonly<Record<string, string>>;
|
|
68
|
+
/**
|
|
69
|
+
* SSR `noExternal` (workerd suites list `hono`, `chanfana` and their scope).
|
|
70
|
+
* Passed through untouched.
|
|
71
|
+
*/
|
|
72
|
+
readonly ssrNoExternal?: readonly string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Build the integration-suite config.
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* // test/integration/vitest.config.mts — workerd suite
|
|
80
|
+
* import { cloudflareTest, cloudflarePool } from '@cloudflare/vitest-pool-workers';
|
|
81
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
82
|
+
* export default defineIntegrationVitestConfig({
|
|
83
|
+
* scope: '@myapp',
|
|
84
|
+
* define: { __INTEGRATION_MIGRATION_SQL__: JSON.stringify(migrationSql) },
|
|
85
|
+
* plugins: [cloudflareTest({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } })],
|
|
86
|
+
* pool: cloudflarePool({ wrangler: { configPath: './test/integration/wrangler.test.jsonc' } }),
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* // test/integration/vitest.config.mts — sqlite suite (no workerd)
|
|
92
|
+
* import { defineIntegrationVitestConfig } from '@rexezuge/tooling/vitest-integration';
|
|
93
|
+
* export default defineIntegrationVitestConfig({
|
|
94
|
+
* scope: '@myapp',
|
|
95
|
+
* include: ['test/integration/**/*.test.ts'],
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function defineIntegrationVitestConfig(options: IntegrationVitestConfigOptions): ReturnType<typeof defineConfig> {
|
|
100
|
+
const root = options.root ?? new URL('.', import.meta.url).href;
|
|
101
|
+
const aliases = [
|
|
102
|
+
...workspaceAliases({ scope: options.scope, root, packages: options.packages ?? DEFAULT_WORKSPACE_PACKAGES, mocks: [] }),
|
|
103
|
+
...(options.aliases ?? []),
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
return defineConfig({
|
|
107
|
+
...(options.define !== undefined && { define: { ...options.define } }),
|
|
108
|
+
...(options.plugins !== undefined && { plugins: [...options.plugins] }),
|
|
109
|
+
resolve: { alias: aliases },
|
|
110
|
+
test: {
|
|
111
|
+
globals: true,
|
|
112
|
+
environment: 'node',
|
|
113
|
+
include: [...(options.include ?? ['test/integration/**/*.int.test.ts'])],
|
|
114
|
+
...(options.pool !== undefined && { pool: options.pool }),
|
|
115
|
+
},
|
|
116
|
+
...(options.ssrNoExternal !== undefined && { ssr: { noExternal: [...options.ssrNoExternal] } }),
|
|
117
|
+
});
|
|
118
|
+
}
|