@ereo/testing 0.1.6

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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @ereo/testing - Snapshot Testing
3
+ *
4
+ * Utilities for snapshot testing loaders and actions.
5
+ */
6
+ import type { LoaderFunction, ActionFunction, RouteParams } from '@ereo/core';
7
+ import { type LoaderTestOptions } from './loader';
8
+ import { type ActionTestOptions } from './action';
9
+ /**
10
+ * Snapshot options.
11
+ */
12
+ export interface SnapshotOptions {
13
+ /** Fields to exclude from snapshot */
14
+ exclude?: string[];
15
+ /** Fields to include in snapshot (if specified, only these are included) */
16
+ include?: string[];
17
+ /** Custom serializer */
18
+ serialize?: (data: unknown) => string;
19
+ /** Replace dynamic values */
20
+ replacers?: Record<string, unknown>;
21
+ }
22
+ /**
23
+ * Create a snapshot of loader data.
24
+ *
25
+ * @example
26
+ * test('loader snapshot', async () => {
27
+ * const snapshot = await snapshotLoader(loader, {
28
+ * params: { slug: 'test-post' },
29
+ * }, {
30
+ * exclude: ['createdAt', 'updatedAt'],
31
+ * replacers: { id: '[ID]' },
32
+ * });
33
+ *
34
+ * expect(snapshot).toMatchSnapshot();
35
+ * });
36
+ */
37
+ export declare function snapshotLoader<T = unknown, P = RouteParams>(loader: LoaderFunction<T, P>, testOptions?: LoaderTestOptions<P>, snapshotOptions?: SnapshotOptions): Promise<unknown>;
38
+ /**
39
+ * Create a snapshot of action result.
40
+ *
41
+ * @example
42
+ * test('action snapshot', async () => {
43
+ * const snapshot = await snapshotAction(action, {
44
+ * formData: { title: 'Test', content: 'Content' },
45
+ * }, {
46
+ * exclude: ['id', 'createdAt'],
47
+ * });
48
+ *
49
+ * expect(snapshot).toMatchSnapshot();
50
+ * });
51
+ */
52
+ export declare function snapshotAction<T = unknown, P = RouteParams>(action: ActionFunction<T | Response, P>, testOptions?: ActionTestOptions<P>, snapshotOptions?: SnapshotOptions): Promise<unknown>;
53
+ /**
54
+ * Create a snapshot object for multiple test scenarios.
55
+ *
56
+ * @example
57
+ * const snapshots = await createSnapshotMatrix(loader, {
58
+ * scenarios: {
59
+ * 'loads featured posts': { params: { featured: 'true' } },
60
+ * 'loads recent posts': { params: { sort: 'recent' } },
61
+ * 'loads by author': { params: { author: 'test-user' } },
62
+ * },
63
+ * });
64
+ *
65
+ * expect(snapshots).toMatchSnapshot();
66
+ */
67
+ export declare function createSnapshotMatrix<T = unknown, P = RouteParams>(loader: LoaderFunction<T, P>, options: {
68
+ scenarios: Record<string, LoaderTestOptions<P>>;
69
+ snapshotOptions?: SnapshotOptions;
70
+ }): Promise<Record<string, unknown>>;
71
+ /**
72
+ * Common replacers for dynamic values.
73
+ */
74
+ export declare const commonReplacers: {
75
+ /** Replace ISO date strings */
76
+ date: RegExp;
77
+ /** Replace UUIDs */
78
+ uuid: RegExp;
79
+ /** Replace numeric IDs */
80
+ numericId: RegExp;
81
+ };
82
+ /**
83
+ * Apply string replacements for snapshot stability.
84
+ *
85
+ * @example
86
+ * const stableData = applyReplacements(data, {
87
+ * [commonReplacers.date]: '[DATE]',
88
+ * [commonReplacers.uuid]: '[UUID]',
89
+ * });
90
+ */
91
+ export declare function applyReplacements(data: unknown, replacements: Record<string, string>): unknown;
92
+ /**
93
+ * Create a deterministic snapshot by sorting object keys.
94
+ */
95
+ export declare function deterministicSnapshot(data: unknown): string;
96
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,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EpB,0BAA0B;;CAE3B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAST;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAY3D"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@ereo/testing",
3
+ "version": "0.1.6",
4
+ "license": "MIT",
5
+ "author": "Ereo Team",
6
+ "homepage": "https://ereo.dev",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ereojs/ereo.git",
10
+ "directory": "packages/testing"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ereojs/ereo/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "bun build ./src/index.ts --outdir ./dist --target bun --external @ereo/core --external @ereo/router --external @ereo/data --external @ereo/server --external react && bun run build:types",
29
+ "build:types": "tsc --emitDeclarationOnly --outDir dist",
30
+ "dev": "bun build ./src/index.ts --outdir ./dist --target bun --watch",
31
+ "test": "bun test",
32
+ "typecheck": "tsc --noEmit --skipLibCheck"
33
+ },
34
+ "dependencies": {
35
+ "@ereo/core": "workspace:*",
36
+ "@ereo/router": "workspace:*",
37
+ "@ereo/data": "workspace:*"
38
+ },
39
+ "devDependencies": {
40
+ "@types/bun": "^1.1.0",
41
+ "typescript": "^5.4.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": "^18.0.0"
45
+ }
46
+ }