@clipboard-health/testing-core 2.9.4 → 2.10.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 +31 -0
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/contractFixtures.d.ts +12 -0
- package/src/lib/contractFixtures.js +11 -0
- package/src/lib/contractFixtures.js.map +1 -0
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ TypeScript-friendly testing utilities.
|
|
|
6
6
|
|
|
7
7
|
- [Install](#install)
|
|
8
8
|
- [Usage](#usage)
|
|
9
|
+
- [Contract fixtures](#contract-fixtures)
|
|
9
10
|
- [Type narrowing `expect` helpers](#type-narrowing-expect-helpers)
|
|
10
11
|
- [Local development commands](#local-development-commands)
|
|
11
12
|
|
|
@@ -17,6 +18,36 @@ npm install @clipboard-health/testing-core
|
|
|
17
18
|
|
|
18
19
|
## Usage
|
|
19
20
|
|
|
21
|
+
### Contract fixtures
|
|
22
|
+
|
|
23
|
+
Parse API response fixtures through their producer-owned Zod contract so drift fails when the
|
|
24
|
+
fixture is constructed. Use `buildContractFixture` for one-off fixtures:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { FeatureResponseSchema } from "@clipboard-health/contract-feature";
|
|
28
|
+
import { buildContractFixture } from "@clipboard-health/testing-core";
|
|
29
|
+
|
|
30
|
+
export const mockFeature = buildContractFixture({
|
|
31
|
+
schema: FeatureResponseSchema,
|
|
32
|
+
fixture: { id: "feature-id" },
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use `createContractFixtureBuilder` for fixture families with shallow overrides:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createContractFixtureBuilder } from "@clipboard-health/testing-core";
|
|
40
|
+
|
|
41
|
+
const buildFeature = createContractFixtureBuilder({
|
|
42
|
+
schema: FeatureResponseSchema,
|
|
43
|
+
defaults: { id: "default-id", name: "Default" },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const mockRenamedFeature = buildFeature({ name: "Renamed" });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Both helpers accept schema input and return schema output, including Zod transforms.
|
|
50
|
+
|
|
20
51
|
### Type narrowing `expect` helpers
|
|
21
52
|
|
|
22
53
|
Jest's [`expect(...).toBeDefined()`](https://jestjs.io/docs/expect#tobedefined) does not narrow types.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/testing-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"description": "TypeScript-friendly testing utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expect",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@clipboard-health/util-ts": "5.
|
|
24
|
+
"@clipboard-health/util-ts": "5.15.1",
|
|
25
25
|
"tslib": "2.8.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/contractFixtures"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./lib/expectToBeDefined"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/expectToBeFailure"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/expectToBeLeft"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/testing-core/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,kEAAwC;AACxC,+DAAqC;AACrC,gEAAsC;AACtC,yEAA+C;AAC/C,2EAAiD;AACjD,kEAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/testing-core/src/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC;AACvC,kEAAwC;AACxC,kEAAwC;AACxC,+DAAqC;AACrC,gEAAsC;AACtC,yEAA+C;AAC/C,2EAAiD;AACjD,kEAAwC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
interface BuildContractFixtureRequest<Input, Output> {
|
|
3
|
+
fixture: Input;
|
|
4
|
+
schema: z.ZodType<Output, z.ZodTypeDef, Input>;
|
|
5
|
+
}
|
|
6
|
+
interface CreateContractFixtureBuilderRequest<Input extends object, Output> {
|
|
7
|
+
defaults: Input;
|
|
8
|
+
schema: z.ZodType<Output, z.ZodTypeDef, Input>;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildContractFixture<Input, Output>({ fixture, schema, }: BuildContractFixtureRequest<Input, Output>): Output;
|
|
11
|
+
export declare function createContractFixtureBuilder<Input extends object, Output>({ defaults, schema, }: CreateContractFixtureBuilderRequest<Input, Output>): (overrides?: Partial<Input>) => Output;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildContractFixture = buildContractFixture;
|
|
4
|
+
exports.createContractFixtureBuilder = createContractFixtureBuilder;
|
|
5
|
+
function buildContractFixture({ fixture, schema, }) {
|
|
6
|
+
return schema.parse(fixture);
|
|
7
|
+
}
|
|
8
|
+
function createContractFixtureBuilder({ defaults, schema, }) {
|
|
9
|
+
return (overrides = {}) => buildContractFixture({ fixture: { ...defaults, ...overrides }, schema });
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=contractFixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contractFixtures.js","sourceRoot":"","sources":["../../../../../packages/testing-core/src/lib/contractFixtures.ts"],"names":[],"mappings":";;;;AAYA,8BAAoD,EAClD,OAAO,EACP,MAAM,GACqC;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,sCAA2E,EACzE,QAAQ,EACR,MAAM,GAC6C;IACnD,OAAO,CAAC,SAAS,GAAG,EAAE,EAAU,EAAE,CAChC,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7E,CAAC"}
|