@happyvertical/smrt-vitest 0.30.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/dist/a11y.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Accessibility assertion helper for component tests (Sweep S11, #1416).
3
+ *
4
+ * Runs axe-core against a rendered container and fails the test with a readable
5
+ * report if any violations are found. Use after a Testing Library `render()`:
6
+ *
7
+ * import { render } from '@testing-library/svelte';
8
+ * import { expectNoA11yViolations } from '@happyvertical/smrt-vitest/a11y';
9
+ *
10
+ * const { container } = render(MyComponent, { props });
11
+ * await expectNoA11yViolations(container);
12
+ *
13
+ * `color-contrast` is disabled by default: jsdom has no layout/paint engine, so
14
+ * contrast can't be computed and the rule produces non-deterministic noise.
15
+ * Pass `{ rules: { 'color-contrast': { enabled: true } } }` to override.
16
+ */
17
+ import axe from 'axe-core';
18
+ export declare function expectNoA11yViolations(container: HTMLElement, options?: axe.RunOptions): Promise<void>;
19
+ //# sourceMappingURL=a11y.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y.d.ts","sourceRoot":"","sources":["../src/a11y.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,GAAG,MAAM,UAAU,CAAC;AAG3B,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,GAAG,CAAC,UAAe,GAC3B,OAAO,CAAC,IAAI,CAAC,CAsBf"}
package/dist/a11y.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Accessibility assertion helper for component tests (Sweep S11, #1416).
3
+ *
4
+ * Runs axe-core against a rendered container and fails the test with a readable
5
+ * report if any violations are found. Use after a Testing Library `render()`:
6
+ *
7
+ * import { render } from '@testing-library/svelte';
8
+ * import { expectNoA11yViolations } from '@happyvertical/smrt-vitest/a11y';
9
+ *
10
+ * const { container } = render(MyComponent, { props });
11
+ * await expectNoA11yViolations(container);
12
+ *
13
+ * `color-contrast` is disabled by default: jsdom has no layout/paint engine, so
14
+ * contrast can't be computed and the rule produces non-deterministic noise.
15
+ * Pass `{ rules: { 'color-contrast': { enabled: true } } }` to override.
16
+ */
17
+ import axe from 'axe-core';
18
+ import { expect } from 'vitest';
19
+ export async function expectNoA11yViolations(container, options = {}) {
20
+ const results = await axe.run(container, {
21
+ ...options,
22
+ // Merge rules last so caller-supplied rules extend (not replace) the
23
+ // color-contrast default; pass `{ 'color-contrast': { enabled: true } }` to
24
+ // opt back in.
25
+ rules: { 'color-contrast': { enabled: false }, ...options.rules },
26
+ });
27
+ if (results.violations.length > 0) {
28
+ const report = results.violations
29
+ .map((v) => {
30
+ const targets = v.nodes
31
+ .map((n) => ` - ${n.target.join(' ')}`)
32
+ .join('\n');
33
+ return ` [${v.id}] ${v.help}\n ${v.helpUrl}\n${targets}`;
34
+ })
35
+ .join('\n');
36
+ expect.fail(`axe found ${results.violations.length} accessibility violation(s):\n${report}`);
37
+ }
38
+ }
39
+ //# sourceMappingURL=a11y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a11y.js","sourceRoot":"","sources":["../src/a11y.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAsB,EACtB,UAA0B,EAAE;IAE5B,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE;QACvC,GAAG,OAAO;QACV,qEAAqE;QACrE,4EAA4E;QAC5E,eAAe;QACf,KAAK,EAAE,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE;KAClE,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK;iBACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;iBAC3C,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,OAAO,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;QAC/D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,CAAC,IAAI,CACT,aAAa,OAAO,CAAC,UAAU,CAAC,MAAM,iCAAiC,MAAM,EAAE,CAChF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * SMRT Vitest Plugin
3
+ *
4
+ * Automatically loads manifests from SMRT peer dependencies before tests run.
5
+ * This solves Issue #583 where cross-package integration tests fail because
6
+ * external package classes aren't registered in the test manifest.
7
+ *
8
+ * Uses ManifestManager for unified manifest loading, which properly handles
9
+ * the manifest priority order: .smrt/manifest.json (test) -> dist/manifest.json (production)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // vitest.config.ts
14
+ * import { defineConfig } from 'vitest/config';
15
+ * import { smrtVitestPlugin } from '@happyvertical/smrt-vitest';
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [smrtVitestPlugin()],
19
+ * test: {
20
+ * globals: true,
21
+ * environment: 'node',
22
+ * },
23
+ * });
24
+ * ```
25
+ *
26
+ * @packageDocumentation
27
+ */
28
+ import type { Plugin } from 'vitest/config';
29
+ /**
30
+ * Configuration options for {@link smrtVitestPlugin} and
31
+ * {@link setupSmrtManifests}.
32
+ *
33
+ * All fields are optional — the defaults work for the typical single-package
34
+ * SMRT project. Override them when you need to tune manifest generation,
35
+ * add extra packages, or adjust the scan scope.
36
+ */
37
+ export interface SmrtVitestPluginOptions {
38
+ /**
39
+ * Extra `@happyvertical/smrt-*` package names whose manifests should be
40
+ * loaded in addition to those discovered automatically from `package.json`.
41
+ *
42
+ * Useful when a dependency is not listed in `dependencies`,
43
+ * `peerDependencies`, or `devDependencies` but still needs its classes
44
+ * registered (e.g., a dynamically loaded plugin).
45
+ *
46
+ * @default [] — only auto-discovered packages are loaded
47
+ */
48
+ packages?: string[];
49
+ /**
50
+ * Emit diagnostic log lines for each manifest discovered, loaded, or
51
+ * skipped. Helpful when debugging "No field metadata found" errors.
52
+ *
53
+ * @default false
54
+ */
55
+ verbose?: boolean;
56
+ /**
57
+ * Project root used to locate `package.json` and to resolve relative
58
+ * manifest paths.
59
+ *
60
+ * @default process.cwd()
61
+ */
62
+ root?: string;
63
+ /**
64
+ * Automatically generate the local manifest at vitest startup using
65
+ * `ManifestBuilder`. When `true`, there is no need to run
66
+ * `smrt generate:test` or `smrt test` before running vitest.
67
+ *
68
+ * The manifest is generated **once** at startup and cached for the session.
69
+ * In watch mode, restart vitest after adding new `@smrt()` classes or
70
+ * fields to pick up the changes.
71
+ *
72
+ * @default true
73
+ */
74
+ generateManifest?: boolean;
75
+ /**
76
+ * Glob patterns that determine which source files are scanned for SMRT
77
+ * classes when `generateManifest` is `true`.
78
+ *
79
+ * @default ['src/**\/*.ts']
80
+ */
81
+ include?: string[];
82
+ /**
83
+ * Glob patterns excluded from the manifest scan.
84
+ *
85
+ * @default ['**\/*.d.ts', '**\/node_modules/**', '**\/dist/**']
86
+ */
87
+ exclude?: string[];
88
+ /**
89
+ * Override the setup file injected into Vitest projects.
90
+ *
91
+ * Defaults to the published package entry. Workspace packages can point this
92
+ * at a local source file while still using the same plugin API.
93
+ */
94
+ setupFile?: string;
95
+ }
96
+ type ViteAliasEntry = {
97
+ find: string;
98
+ replacement: string;
99
+ };
100
+ export declare function getWorkspaceViteAliases(root?: string): ViteAliasEntry[];
101
+ /**
102
+ * Create the SMRT Vitest plugin
103
+ *
104
+ * This plugin automatically generates and loads manifests before tests run,
105
+ * enabling cross-package integration tests without needing to run `smrt test` first.
106
+ *
107
+ * @param options - Plugin configuration options
108
+ * @returns Vitest plugin
109
+ *
110
+ * @example Basic usage
111
+ * ```typescript
112
+ * import { defineConfig } from 'vitest/config';
113
+ * import { smrtVitestPlugin } from '@happyvertical/smrt-vitest';
114
+ *
115
+ * export default defineConfig({
116
+ * plugins: [smrtVitestPlugin()],
117
+ * });
118
+ * ```
119
+ *
120
+ * @example With additional packages
121
+ * ```typescript
122
+ * import { defineConfig } from 'vitest/config';
123
+ * import { smrtVitestPlugin } from '@happyvertical/smrt-vitest';
124
+ *
125
+ * export default defineConfig({
126
+ * plugins: [
127
+ * smrtVitestPlugin({
128
+ * packages: ['@my-org/custom-smrt-package'],
129
+ * verbose: true,
130
+ * }),
131
+ * ],
132
+ * });
133
+ * ```
134
+ *
135
+ * @example Disable auto-generation (use pre-built manifest)
136
+ * ```typescript
137
+ * export default defineConfig({
138
+ * plugins: [
139
+ * smrtVitestPlugin({
140
+ * generateManifest: false, // Use existing manifest only
141
+ * }),
142
+ * ],
143
+ * });
144
+ * ```
145
+ */
146
+ export declare function smrtVitestPlugin(options?: SmrtVitestPluginOptions): Plugin;
147
+ /**
148
+ * Discover and register SMRT manifests from peer dependencies.
149
+ *
150
+ * An imperative alternative to {@link smrtVitestPlugin} for environments
151
+ * where a Vite plugin is not available (e.g., a plain `globalSetup` file or
152
+ * a custom test runner bootstrap).
153
+ *
154
+ * The function reads `package.json` in the working directory, finds all
155
+ * `@happyvertical/smrt-*` dependencies, locates their manifest files, and
156
+ * registers every class in the global `ObjectRegistry`. It does **not**
157
+ * generate a new manifest — use `smrtVitestPlugin()` with
158
+ * `generateManifest: true` (the default) if auto-generation is needed.
159
+ *
160
+ * @param options - Same options accepted by {@link smrtVitestPlugin}.
161
+ * Relevant fields: `packages`, `verbose`, `root`.
162
+ * @returns A promise that resolves once all manifests have been loaded.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * // vitest.config.ts
167
+ * import { defineConfig } from 'vitest/config';
168
+ *
169
+ * export default defineConfig({
170
+ * test: {
171
+ * globalSetup: ['@happyvertical/smrt-vitest/setup'],
172
+ * },
173
+ * });
174
+ * ```
175
+ *
176
+ * @example Calling directly in a custom bootstrap
177
+ * ```typescript
178
+ * import { setupSmrtManifests } from '@happyvertical/smrt-vitest';
179
+ *
180
+ * await setupSmrtManifests({ verbose: true });
181
+ * ```
182
+ *
183
+ * @see {@link smrtVitestPlugin} for the recommended Vite-plugin approach that
184
+ * also handles manifest generation.
185
+ */
186
+ export declare function setupSmrtManifests(options?: SmrtVitestPluginOptions): Promise<void>;
187
+ export default smrtVitestPlugin;
188
+ export { createIsolatedTestDb, createIsolatedTestDbFromManifest, createTestDb, getAdapterDisplayName, getInMemoryDbConfig, getTestAdapter, getTestDbConfig, type IsolatedTestDbOptions, type IsolatedTestDbResult, isPostgresAvailable, type ManifestTestDbOptions, type TestDbAdapter, type TestDbConfig, } from './test-db.js';
189
+ export type { TransactionHandle } from './types.js';
190
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAE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