@rexezuge/tooling 1.2.0 → 1.3.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 +19 -3
- package/dist/eslint-boundaries.d.ts.map +1 -1
- package/dist/eslint-boundaries.js +89 -3
- package/dist/eslint-boundaries.js.map +1 -1
- package/dist/eslint.d.ts +12 -7
- package/dist/eslint.d.ts.map +1 -1
- package/dist/eslint.js +13 -8
- package/dist/eslint.js.map +1 -1
- package/dist/index.d.ts +20 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/scripts/backup/d1-target.js +1 -1
- package/dist/scripts/backup/d1-target.js.map +1 -1
- package/dist/scripts/backup/encrypt-backup.js +2 -2
- package/dist/scripts/backup/encrypt-backup.js.map +1 -1
- package/dist/scripts/check-god-files.js +2 -2
- package/dist/scripts/check-god-files.js.map +1 -1
- package/dist/scripts/ensure-spa-shell-stub.js +1 -1
- package/dist/scripts/ensure-spa-shell-stub.js.map +1 -1
- package/dist/scripts/init-secrets.d.ts +1 -1
- package/dist/scripts/init-secrets.d.ts.map +1 -1
- package/dist/scripts/init-secrets.js +3 -3
- package/dist/scripts/init-secrets.js.map +1 -1
- package/dist/scripts/migrations-lock.js +1 -1
- package/dist/scripts/migrations-lock.js.map +1 -1
- package/dist/scripts/prepare-wrangler-config.js +3 -3
- package/dist/scripts/prepare-wrangler-config.js.map +1 -1
- package/dist/scripts/verify-spa-shell.js +1 -1
- package/dist/scripts/verify-spa-shell.js.map +1 -1
- package/dist/scripts/wrangler-config/patches.d.ts +1 -1
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/patches.js +1 -1
- package/dist/scripts/wrangler-config/patches.js.map +1 -1
- package/dist/scripts/wrangler-config/resources.d.ts +1 -1
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
- package/dist/scripts/wrangler-config/resources.js +4 -4
- package/dist/scripts/wrangler-config/resources.js.map +1 -1
- package/dist/vitest-aliases.d.ts +90 -0
- package/dist/vitest-aliases.d.ts.map +1 -0
- package/dist/vitest-aliases.js +81 -0
- package/dist/vitest-aliases.js.map +1 -0
- package/dist/vitest-integration.d.ts +96 -0
- package/dist/vitest-integration.d.ts.map +1 -0
- package/dist/vitest-integration.js +64 -0
- package/dist/vitest-integration.js.map +1 -0
- package/dist/vitest-repo.d.ts +154 -0
- package/dist/vitest-repo.d.ts.map +1 -0
- package/dist/vitest-repo.js +146 -0
- package/dist/vitest-repo.js.map +1 -0
- package/dist/vitest-web.d.ts +76 -19
- package/dist/vitest-web.d.ts.map +1 -1
- package/dist/vitest-web.js +62 -25
- package/dist/vitest-web.js.map +1 -1
- package/dist/vitest.d.ts +70 -19
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +42 -37
- package/dist/vitest.js.map +1 -1
- package/package.json +8 -2
- package/src/eslint-boundaries.ts +99 -6
- package/src/eslint.test.ts +22 -1
- package/src/eslint.ts +14 -9
- package/src/functions/pages-proxy.test.ts +2 -2
- package/src/index.ts +23 -14
- package/src/scripts/backup/backup-rules.test.ts +3 -3
- package/src/scripts/backup/d1-target.ts +1 -1
- package/src/scripts/backup/encrypt-backup.ts +2 -2
- package/src/scripts/check-god-files.test.ts +1 -1
- package/src/scripts/check-god-files.ts +2 -2
- package/src/scripts/ensure-spa-shell-stub.ts +1 -1
- package/src/scripts/init-secrets.ts +3 -3
- package/src/scripts/migrations-lock.ts +1 -1
- package/src/scripts/prepare-wrangler-config.ts +3 -3
- package/src/scripts/spa-shell.test.ts +1 -1
- package/src/scripts/validate-locales.test.ts +1 -1
- package/src/scripts/verify-migrations.test.ts +1 -1
- package/src/scripts/verify-spa-shell.ts +1 -1
- package/src/scripts/wrangler-config/patches.ts +1 -1
- package/src/scripts/wrangler-config/resources.ts +4 -4
- package/src/test/integration-migrations.test.ts +1 -1
- package/src/vite.test.ts +1 -1
- package/src/vitest-aliases.test.ts +53 -0
- package/src/vitest-aliases.ts +127 -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/index.ts
CHANGED
|
@@ -15,30 +15,39 @@
|
|
|
15
15
|
* alongside `@rexezuge/d1`.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
export { defineRepoLintConfig } from './eslint';
|
|
19
|
-
export type { RepoLintConfigOptions } from './eslint';
|
|
18
|
+
export { defineRepoLintConfig } from './eslint.ts';
|
|
19
|
+
export type { RepoLintConfigOptions } from './eslint.ts';
|
|
20
20
|
|
|
21
|
-
export { defineUnitVitestConfig } from './vitest';
|
|
22
|
-
export type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest';
|
|
21
|
+
export { defineUnitVitestConfig } from './vitest.ts';
|
|
22
|
+
export type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest.ts';
|
|
23
23
|
|
|
24
|
-
export { defineWebVitestConfig } from './vitest-web';
|
|
25
|
-
export type { WebVitestConfigOptions } from './vitest-web';
|
|
24
|
+
export { defineWebVitestConfig } from './vitest-web.ts';
|
|
25
|
+
export type { WebVitestConfigOptions } from './vitest-web.ts';
|
|
26
26
|
|
|
27
|
-
export {
|
|
28
|
-
export type {
|
|
27
|
+
export { defineRepoVitestConfig } from './vitest-repo.ts';
|
|
28
|
+
export type { RepoBackendOptions, RepoVitestConfigOptions, RepoWebOptions } from './vitest-repo.ts';
|
|
29
29
|
|
|
30
|
-
export {
|
|
31
|
-
export type {
|
|
30
|
+
export { defineIntegrationVitestConfig } from './vitest-integration.ts';
|
|
31
|
+
export type { IntegrationVitestConfigOptions } from './vitest-integration.ts';
|
|
32
|
+
|
|
33
|
+
export { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';
|
|
34
|
+
export type { VitestAlias as WorkspaceAlias, WorkspaceAliasesOptions } from './vitest-aliases.ts';
|
|
35
|
+
|
|
36
|
+
export { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';
|
|
37
|
+
export type { ProxyEntry, SpaShellTarget, WebViteConfigOptions } from './vite.ts';
|
|
38
|
+
|
|
39
|
+
export { createPagesProxy } from './functions/pages-proxy.ts';
|
|
40
|
+
export type { Fetcher, PagesFunction, PagesFunctionContext, PagesProxyEnv, PagesProxyOptions } from './functions/pages-proxy.ts';
|
|
32
41
|
|
|
33
42
|
// --- Test helpers ---------------------------------------------------------
|
|
34
43
|
//
|
|
35
44
|
// Aliased in a Vitest config, not imported by application code, so the mocks stay
|
|
36
45
|
// where the suites can reach them.
|
|
37
46
|
|
|
38
|
-
export { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers';
|
|
39
|
-
export type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers';
|
|
47
|
+
export { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers.ts';
|
|
48
|
+
export type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers.ts';
|
|
40
49
|
|
|
41
|
-
export { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations';
|
|
50
|
+
export { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations.ts';
|
|
42
51
|
export type {
|
|
43
52
|
D1DatabaseLike,
|
|
44
53
|
D1PreparedStatementLike,
|
|
@@ -46,4 +55,4 @@ export type {
|
|
|
46
55
|
MigrationHelper,
|
|
47
56
|
MigrationHelperOptions,
|
|
48
57
|
MigrationRange,
|
|
49
|
-
} from './test/integration-migrations';
|
|
58
|
+
} from './test/integration-migrations.ts';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { resolveD1Target } from './d1-target';
|
|
3
|
-
import { evaluateConfig } from './destination-config';
|
|
4
|
-
import { backupFileName, backupStamp, requireRetentionDays, retentionCutoff } from './naming';
|
|
2
|
+
import { resolveD1Target } from './d1-target.ts';
|
|
3
|
+
import { evaluateConfig } from './destination-config.ts';
|
|
4
|
+
import { backupFileName, backupStamp, requireRetentionDays, retentionCutoff } from './naming.ts';
|
|
5
5
|
|
|
6
6
|
describe('resolveD1Target', () => {
|
|
7
7
|
it('prefers database_name, falling back to the binding', () => {
|
|
@@ -36,8 +36,8 @@ import { encryptSecret } from '@rexezuge/d1';
|
|
|
36
36
|
import { execFileSync } from 'node:child_process';
|
|
37
37
|
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
38
38
|
import { basename } from 'node:path';
|
|
39
|
-
import { fail, setOutput } from '../lib/github-actions';
|
|
40
|
-
import { backupFileName } from './naming';
|
|
39
|
+
import { fail, setOutput } from '../lib/github-actions.ts';
|
|
40
|
+
import { backupFileName } from './naming.ts';
|
|
41
41
|
|
|
42
42
|
/** The dump the export step leaves in the working directory. */
|
|
43
43
|
const SOURCE_FILE = 'backup.sql';
|
|
@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { checkGodFiles, checkGodFilesCli, readAllowlist, HARD_LIMIT, SOFT_LIMIT } from './check-god-files';
|
|
5
|
+
import { checkGodFiles, checkGodFilesCli, readAllowlist, HARD_LIMIT, SOFT_LIMIT } from './check-god-files.ts';
|
|
6
6
|
|
|
7
7
|
function tempTree(files: Record<string, string>): string {
|
|
8
8
|
const root = mkdtempSync(join(tmpdir(), 'god-files-'));
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
50
50
|
import { pathToFileURL } from 'node:url';
|
|
51
51
|
import { join, relative } from 'node:path';
|
|
52
|
-
import { fail } from './lib/github-actions';
|
|
53
|
-
import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args';
|
|
52
|
+
import { fail } from './lib/github-actions.ts';
|
|
53
|
+
import { isSet, parseFlags, splitPositional, valueOf } from './lib/cli-args.ts';
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* A file past a size the guard reports on.
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import path from 'node:path';
|
|
22
22
|
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { ensureSpaShellStub } from './spa-shell';
|
|
23
|
+
import { ensureSpaShellStub } from './spa-shell.ts';
|
|
24
24
|
|
|
25
25
|
const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
26
26
|
const root = process.argv[2] === undefined ? REPOSITORY_ROOT : path.resolve(process.argv[2]);
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
import { execFileSync } from 'node:child_process';
|
|
48
48
|
import { existsSync, readFileSync } from 'node:fs';
|
|
49
49
|
import { parse } from 'jsonc-parser';
|
|
50
|
-
import { fail } from './lib/github-actions';
|
|
51
|
-
import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table';
|
|
52
|
-
import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types';
|
|
50
|
+
import { fail } from './lib/github-actions.ts';
|
|
51
|
+
import { isEmptySecretsStoreListing, parseWranglerNames } from './lib/wrangler-table.ts';
|
|
52
|
+
import { CONFIG_PATH, type WranglerConfig } from './wrangler-config/types.ts';
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* The secret names the AES-GCM key generator produces, matched by **shape**.
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import path from 'node:path';
|
|
31
31
|
import { fileURLToPath } from 'node:url';
|
|
32
|
-
import { LOCK_NAME, verifyMigrations } from './verify-migrations';
|
|
32
|
+
import { LOCK_NAME, verifyMigrations } from './verify-migrations.ts';
|
|
33
33
|
|
|
34
34
|
const REPOSITORY_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
35
35
|
const migrationsDir = process.argv[2] === undefined ? path.join(REPOSITORY_ROOT, 'migrations') : path.resolve(process.argv[2]);
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
* - `WRANGLER_PATCH_JSON` — top-level keys merged into the config.
|
|
32
32
|
* - `WRANGLER_VARS_PATCH_JSON` — `vars` entries merged into the config.
|
|
33
33
|
*/
|
|
34
|
-
import { setOutput } from './lib/github-actions';
|
|
35
|
-
import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches';
|
|
36
|
-
import { provisionWranglerResources } from './wrangler-config/resources';
|
|
34
|
+
import { setOutput } from './lib/github-actions.ts';
|
|
35
|
+
import { applyTopLevelPatch, applyVarsPatch, ensureMinimumConfigVersion, prepareConfigFile } from './wrangler-config/patches.ts';
|
|
36
|
+
import { provisionWranglerResources } from './wrangler-config/resources.ts';
|
|
37
37
|
|
|
38
38
|
prepareConfigFile();
|
|
39
39
|
ensureMinimumConfigVersion();
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { ensureSpaShellStub, spaShellCli, verifySpaShell } from './spa-shell';
|
|
5
|
+
import { ensureSpaShellStub, spaShellCli, verifySpaShell } from './spa-shell.ts';
|
|
6
6
|
|
|
7
7
|
function tempTree(): string {
|
|
8
8
|
return mkdtempSync(join(tmpdir(), 'spa-shell-'));
|
|
@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { parseObjectLiteral, validateLocales, validateLocalesCli } from './validate-locales';
|
|
5
|
+
import { parseObjectLiteral, validateLocales, validateLocalesCli } from './validate-locales.ts';
|
|
6
6
|
|
|
7
7
|
function writeBundles(root: string, locale: string, bundle: Record<string, unknown>): string {
|
|
8
8
|
const dir = join(root, locale);
|
|
@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { verifyMigrations, verifyMigrationsCli, LOCK_NAME } from './verify-migrations';
|
|
5
|
+
import { verifyMigrations, verifyMigrationsCli, LOCK_NAME } from './verify-migrations.ts';
|
|
6
6
|
|
|
7
7
|
function tempMigrations(files: Record<string, string>): string {
|
|
8
8
|
const root = mkdtempSync(join(tmpdir(), 'migrations-'));
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import path from 'node:path';
|
|
33
33
|
import { fileURLToPath } from 'node:url';
|
|
34
|
-
import { verifySpaShell } from './spa-shell';
|
|
34
|
+
import { verifySpaShell } from './spa-shell.ts';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* The repository root, derived from this file rather than from `process.cwd()`.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
14
14
|
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
15
|
-
import { CONFIG_PATH, TEMPLATE_PATH, type WranglerConfig } from './types';
|
|
15
|
+
import { CONFIG_PATH, TEMPLATE_PATH, type WranglerConfig } from './types.ts';
|
|
16
16
|
|
|
17
17
|
/** The config's current text and its parsed form. */
|
|
18
18
|
export interface ConfigFile {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import { writeFileSync } from 'node:fs';
|
|
16
16
|
import { parse } from 'jsonc-parser';
|
|
17
|
-
import { parseWranglerTableRows } from '../lib/wrangler-table';
|
|
17
|
+
import { parseWranglerTableRows } from '../lib/wrangler-table.ts';
|
|
18
18
|
import {
|
|
19
19
|
CONFIG_PATH,
|
|
20
20
|
DEFAULT_HEX_ID,
|
|
@@ -27,9 +27,9 @@ import {
|
|
|
27
27
|
type KVNamespace,
|
|
28
28
|
type SecretStore,
|
|
29
29
|
type WranglerConfig,
|
|
30
|
-
} from './types';
|
|
31
|
-
import { parseJsonArray, runWrangler } from './cli';
|
|
32
|
-
import { readConfig, writeConfig, writeConfigValue } from './patches';
|
|
30
|
+
} from './types.ts';
|
|
31
|
+
import { parseJsonArray, runWrangler } from './cli.ts';
|
|
32
|
+
import { readConfig, writeConfig, writeConfigValue } from './patches.ts';
|
|
33
33
|
|
|
34
34
|
/** What `ensure*` did, so a caller can act on the difference. */
|
|
35
35
|
export interface Provisioned {
|
package/src/vite.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
|
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { dirname, join } 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
|
|
|
@@ -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,127 @@
|
|
|
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}/` });
|
|
124
|
+
aliases.push({ find: /^~\//, replacement: `${webSrc}/` });
|
|
125
|
+
aliases.push(...(options.extraAliases ?? []));
|
|
126
|
+
return aliases;
|
|
127
|
+
}
|
|
@@ -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
|
+
});
|