@catalystiq/test-kit 0.3.0 → 0.3.1
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 +1 -1
- package/dist/setup/README.md +1 -1
- package/dist/setup/config.d.ts +11 -0
- package/dist/setup/config.js +5 -0
- package/dist/setup/dom.d.ts +6 -2
- package/dist/setup/dom.js +17 -1
- package/dist/setup/setup-file.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @catalystiq/test-kit
|
|
2
2
|
|
|
3
|
-
Shared test helpers: one package, added to part by part. Pin an exact version (`"@catalystiq/test-kit": "0.3.
|
|
3
|
+
Shared test helpers: one package, added to part by part. Pin an exact version (`"@catalystiq/test-kit": "0.3.1"`);
|
|
4
4
|
Dependabot raises it.
|
|
5
5
|
|
|
6
6
|
| Part | Import | What |
|
package/dist/setup/README.md
CHANGED
|
@@ -32,7 +32,7 @@ A file that needs a DOM says so on its first line: `// @vitest-environment jsdom
|
|
|
32
32
|
| Production databases | A Postgres URL in the environment whose host is on your production list (a host, a subdomain of it, or a compute endpoint id `ep-…` with or without `-pooler`) is refused before any test runs, and again before the tests (your own setup file may set the URL). |
|
|
33
33
|
| `.env*` files | A Postgres URL in the environment that names the same database as any `.env*` file at the root is refused: those hold a developer's own connections. Every `postgres://` text counts, comments included, except lines keyed by `testDatabaseEnv`. |
|
|
34
34
|
| React warnings | A React or Radix warning (`console.error` / `console.warn`) fails the test, also when the test muted the console (`vi.spyOn(console, 'error').mockImplementation(() => {})`, `console.error = vi.fn()`, `console.error = () => {}`). |
|
|
35
|
-
| DOM files | Under jsdom: a `matchMedia` stub, `localStorage` / `sessionStorage` re-bound on Node 26, Testing Library's `cleanup` after each test, and jest-dom's matchers when installed. |
|
|
35
|
+
| DOM files | Under jsdom: a `matchMedia` stub, `localStorage` / `sessionStorage` re-bound on Node 26, Testing Library's `cleanup` after each test (imported by the setup; with `domCleanup: 'deferred'`, after the first test instead, so a file can put React's devtools hook in place before react-dom loads), and jest-dom's matchers when installed. |
|
|
36
36
|
|
|
37
37
|
## Allowing a React warning
|
|
38
38
|
|
package/dist/setup/config.d.ts
CHANGED
|
@@ -18,6 +18,16 @@ export interface TestKitOptions {
|
|
|
18
18
|
testDatabaseEnv?: string[];
|
|
19
19
|
/** The React-warning allow-list file, relative to `root` (see the README). */
|
|
20
20
|
reactWarningAllowList?: string;
|
|
21
|
+
/**
|
|
22
|
+
* When a jsdom file's Testing Library `cleanup` is imported. `'setup'` (the default): by the setup, once per file.
|
|
23
|
+
* `'deferred'`: after the file's first test, once, so the setup loads no react-dom before the test file, for a file that puts React's
|
|
24
|
+
* devtools hook in place in `vi.hoisted` (React finds the hook only if it is there before react-dom loads). Deferred,
|
|
25
|
+
* cleanup uses the instance first imported after a test; a file that resets modules or mocks Testing Library without
|
|
26
|
+
* a `cleanup` gets none; and under `globals: true`, Testing Library's own `beforeAll` (which marks the environment as
|
|
27
|
+
* React's `act` environment) is not registered for a file that does not import it, so such a file sets
|
|
28
|
+
* `IS_REACT_ACT_ENVIRONMENT` itself.
|
|
29
|
+
*/
|
|
30
|
+
domCleanup?: 'setup' | 'deferred';
|
|
21
31
|
}
|
|
22
32
|
/** What the workers receive. */
|
|
23
33
|
export interface TestKitProvided {
|
|
@@ -31,6 +41,7 @@ export interface TestKitProvided {
|
|
|
31
41
|
pattern: string;
|
|
32
42
|
file?: string;
|
|
33
43
|
}>;
|
|
44
|
+
domCleanup: 'setup' | 'deferred';
|
|
34
45
|
}
|
|
35
46
|
declare module 'vitest' {
|
|
36
47
|
interface ProvidedContext {
|
package/dist/setup/config.js
CHANGED
|
@@ -40,6 +40,10 @@ export function provideFor(options = {}) {
|
|
|
40
40
|
...(options.productionDatabaseHostsFile ? readHostsFile(at(options.productionDatabaseHostsFile)) : []),
|
|
41
41
|
];
|
|
42
42
|
const allowList = options.reactWarningAllowList ? readAllowList(at(options.reactWarningAllowList)) : null;
|
|
43
|
+
const domCleanup = options.domCleanup ?? 'setup';
|
|
44
|
+
if (domCleanup !== 'setup' && domCleanup !== 'deferred') {
|
|
45
|
+
throw new Error(`test-kit: domCleanup must be 'setup' or 'deferred', not ${JSON.stringify(domCleanup)}`);
|
|
46
|
+
}
|
|
43
47
|
return {
|
|
44
48
|
allowHosts: options.allowHosts ?? [],
|
|
45
49
|
allowDatabaseHosts: options.allowDatabaseHosts ?? true,
|
|
@@ -48,6 +52,7 @@ export function provideFor(options = {}) {
|
|
|
48
52
|
productionHosts,
|
|
49
53
|
protectedPlaces: protectedPlaces(root, options.testDatabaseEnv ?? []),
|
|
50
54
|
allowedWarnings: (allowList?.entries ?? []).map((e) => ({ pattern: e.pattern, ...(e.file ? { file: e.file } : {}) })),
|
|
55
|
+
domCleanup,
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
/** The kit's part of a Vitest config. */
|
package/dist/setup/dom.d.ts
CHANGED
|
@@ -7,8 +7,12 @@ export declare function installMatchMedia(): void;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function rebindStorage(): void;
|
|
9
9
|
export interface DomOptions {
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Unmount what Testing Library rendered after each test (it does so itself only under Vitest's globals). Default:
|
|
12
|
+
* true, importing Testing Library now. `'deferred'` imports it after the first test instead (once per file), so this
|
|
13
|
+
* setup loads no react-dom before the test file does (the config's `domCleanup`).
|
|
14
|
+
*/
|
|
15
|
+
cleanup?: boolean | 'deferred';
|
|
12
16
|
/** Load `@testing-library/jest-dom`'s matchers when it is installed. Default: true. */
|
|
13
17
|
jestDom?: boolean;
|
|
14
18
|
}
|
package/dist/setup/dom.js
CHANGED
|
@@ -62,7 +62,23 @@ export async function installDom(options = {}) {
|
|
|
62
62
|
rebindStorage();
|
|
63
63
|
if (options.jestDom ?? true)
|
|
64
64
|
await optionalImport('@testing-library/jest-dom/vitest');
|
|
65
|
-
if (options.cleanup
|
|
65
|
+
if (options.cleanup === 'deferred') {
|
|
66
|
+
let rtl;
|
|
67
|
+
afterEach(async () => {
|
|
68
|
+
rtl ??= optionalImport('@testing-library/react');
|
|
69
|
+
const module = await rtl; // as in setup mode, only a missing module is ignored; any other failure fails the cleanup
|
|
70
|
+
let cleanup;
|
|
71
|
+
try {
|
|
72
|
+
cleanup = module?.cleanup;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// a mock of Testing Library without a cleanup export: nothing to unmount with
|
|
76
|
+
}
|
|
77
|
+
if (typeof cleanup === 'function')
|
|
78
|
+
cleanup();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else if (options.cleanup ?? true) {
|
|
66
82
|
const rtl = await optionalImport('@testing-library/react');
|
|
67
83
|
const cleanup = rtl?.cleanup;
|
|
68
84
|
if (typeof cleanup === 'function')
|
package/dist/setup/setup-file.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catalystiq/test-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Shared test setup for Vitest, a fake MCP Apps host for jsdom and Playwright, the local Neon test-database run, and the local environment guard.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|