@schmock/faker 2.2.3 → 2.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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/constants.d.ts +82 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/field-mappings.d.ts.map +1 -1
- package/dist/field-name-matcher.d.ts +19 -0
- package/dist/field-name-matcher.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/jsf-config.d.ts +27 -2
- package/dist/jsf-config.d.ts.map +1 -1
- package/dist/output-limits.d.ts +3 -0
- package/dist/output-limits.d.ts.map +1 -0
- package/dist/overrides.d.ts +2 -1
- package/dist/overrides.d.ts.map +1 -1
- package/dist/schema-children.d.ts +14 -0
- package/dist/schema-children.d.ts.map +1 -0
- package/dist/schema-enhancement.d.ts +1 -0
- package/dist/schema-enhancement.d.ts.map +1 -1
- package/dist/validation.d.ts +24 -5
- package/dist/validation.d.ts.map +1 -1
- package/package.json +19 -9
- package/dist/constants.js +0 -8
- package/dist/field-mappings.js +0 -1107
- package/dist/field-name-matcher.js +0 -149
- package/dist/jsf-config.js +0 -35
- package/dist/overrides.js +0 -131
- package/dist/schema-enhancement.js +0 -89
- package/dist/test-utils.d.ts +0 -57
- package/dist/test-utils.d.ts.map +0 -1
- package/dist/test-utils.js +0 -271
- package/dist/validation.js +0 -300
- package/src/advanced-features.test.ts +0 -912
- package/src/audit-faker-args.test.ts +0 -97
- package/src/constants.d.ts.map +0 -1
- package/src/constants.ts +0 -9
- package/src/data-quality.test.ts +0 -415
- package/src/error-handling.test.ts +0 -504
- package/src/field-mappings.test.ts +0 -351
- package/src/field-mappings.ts +0 -1141
- package/src/field-name-matcher.test.ts +0 -292
- package/src/field-name-matcher.ts +0 -188
- package/src/index.d.ts.map +0 -1
- package/src/index.test.ts +0 -1218
- package/src/index.ts +0 -168
- package/src/integration.test.ts +0 -634
- package/src/jsf-config.d.ts.map +0 -1
- package/src/jsf-config.ts +0 -48
- package/src/overrides.d.ts.map +0 -1
- package/src/overrides.property.test.ts +0 -172
- package/src/overrides.test.ts +0 -38
- package/src/overrides.ts +0 -176
- package/src/performance.test.ts +0 -494
- package/src/plugin-integration.test.ts +0 -575
- package/src/post-process.test.ts +0 -151
- package/src/real-world.test.ts +0 -636
- package/src/schema-enhancement.d.ts.map +0 -1
- package/src/schema-enhancement.test.ts +0 -216
- package/src/schema-enhancement.ts +0 -128
- package/src/steps/deterministic-seeds.steps.ts +0 -35
- package/src/steps/faker-plugin.steps.ts +0 -109
- package/src/test-utils.ts +0 -365
- package/src/validation.d.ts.map +0 -1
- package/src/validation.ts +0 -417
package/src/post-process.test.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type { JSONSchema7 } from "json-schema";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { generateFromSchema } from "./index";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Tests for postProcessGenerated behavior.
|
|
7
|
-
* Since postProcessGenerated is not exported, we test it indirectly via generateFromSchema.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
describe("postProcessGenerated — schmockNullable", () => {
|
|
11
|
-
it("schema with schmockNullable: true — over 100 runs, some should be null", async () => {
|
|
12
|
-
// We use a schema where the field has schmockNullable set.
|
|
13
|
-
// Since enhanceSchemaWithSmartMapping may add this marker for nullable fields,
|
|
14
|
-
// we test by adding the marker directly through a schema that triggers it.
|
|
15
|
-
// The simplest approach: craft a schema with the x-nullable pattern that
|
|
16
|
-
// enhanceSchemaWithSmartMapping would process, or use a type that gets
|
|
17
|
-
// the schmockNullable marker applied.
|
|
18
|
-
//
|
|
19
|
-
// Since schmockNullable is set by the enhancement layer for nullable fields,
|
|
20
|
-
// we test via a schema with nullable: true (OpenAPI pattern) or anyOf with null.
|
|
21
|
-
// However, the safest approach is to test a field that we know goes through
|
|
22
|
-
// postProcessGenerated with the schmockNullable flag.
|
|
23
|
-
|
|
24
|
-
// Direct approach: construct a schema that includes schmockNullable at the property level
|
|
25
|
-
const schema: JSONSchema7 & Record<string, unknown> = {
|
|
26
|
-
type: "object",
|
|
27
|
-
properties: {
|
|
28
|
-
value: {
|
|
29
|
-
type: "string",
|
|
30
|
-
schmockNullable: true,
|
|
31
|
-
} as JSONSchema7 & { schmockNullable: boolean },
|
|
32
|
-
},
|
|
33
|
-
required: ["value"],
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
let nullCount = 0;
|
|
37
|
-
const runs = 200;
|
|
38
|
-
for (let i = 0; i < runs; i++) {
|
|
39
|
-
const result = (await generateFromSchema({ schema })) as Record<
|
|
40
|
-
string,
|
|
41
|
-
unknown
|
|
42
|
-
>;
|
|
43
|
-
if (result.value === null) {
|
|
44
|
-
nullCount++;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// With NULLABLE_NULL_PROBABILITY = 0.05, over 200 runs we expect ~10 nulls.
|
|
49
|
-
// We use a loose check: at least 1 null (very unlikely to get 0 in 200 trials at 5%)
|
|
50
|
-
expect(nullCount).toBeGreaterThan(0);
|
|
51
|
-
// And not all nulls
|
|
52
|
-
expect(nullCount).toBeLessThan(runs);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("postProcessGenerated — schmockTrueProbability", () => {
|
|
57
|
-
it("schema with schmockTrueProbability: 0.8 — over 100 runs, ~80% should be true", async () => {
|
|
58
|
-
const schema: JSONSchema7 & Record<string, unknown> = {
|
|
59
|
-
type: "object",
|
|
60
|
-
properties: {
|
|
61
|
-
isActive: {
|
|
62
|
-
type: "boolean",
|
|
63
|
-
schmockTrueProbability: 0.8,
|
|
64
|
-
} as JSONSchema7 & { schmockTrueProbability: number },
|
|
65
|
-
},
|
|
66
|
-
required: ["isActive"],
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
let trueCount = 0;
|
|
70
|
-
const runs = 200;
|
|
71
|
-
for (let i = 0; i < runs; i++) {
|
|
72
|
-
const result = (await generateFromSchema({ schema })) as Record<
|
|
73
|
-
string,
|
|
74
|
-
unknown
|
|
75
|
-
>;
|
|
76
|
-
if (result.isActive === true) {
|
|
77
|
-
trueCount++;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const trueRate = trueCount / runs;
|
|
82
|
-
// With probability 0.8, expect trueRate to be roughly in [0.65, 0.95]
|
|
83
|
-
expect(trueRate).toBeGreaterThan(0.55);
|
|
84
|
-
expect(trueRate).toBeLessThan(0.95);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("postProcessGenerated — recursive processing", () => {
|
|
89
|
-
it("nested object properties are recursively processed", async () => {
|
|
90
|
-
const schema: JSONSchema7 = {
|
|
91
|
-
type: "object",
|
|
92
|
-
properties: {
|
|
93
|
-
outer: {
|
|
94
|
-
type: "object",
|
|
95
|
-
properties: {
|
|
96
|
-
inner: {
|
|
97
|
-
type: "boolean",
|
|
98
|
-
schmockTrueProbability: 1.0,
|
|
99
|
-
} as JSONSchema7 & { schmockTrueProbability: number },
|
|
100
|
-
},
|
|
101
|
-
required: ["inner"],
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
required: ["outer"],
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
// With schmockTrueProbability = 1.0, every run should yield true
|
|
108
|
-
for (let i = 0; i < 10; i++) {
|
|
109
|
-
const result = (await generateFromSchema({ schema })) as {
|
|
110
|
-
outer: { inner: boolean };
|
|
111
|
-
};
|
|
112
|
-
expect(result.outer.inner).toBe(true);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("array items are recursively processed", async () => {
|
|
117
|
-
const schema: JSONSchema7 = {
|
|
118
|
-
type: "array",
|
|
119
|
-
items: {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: {
|
|
122
|
-
flag: {
|
|
123
|
-
type: "boolean",
|
|
124
|
-
schmockTrueProbability: 1.0,
|
|
125
|
-
} as JSONSchema7 & { schmockTrueProbability: number },
|
|
126
|
-
},
|
|
127
|
-
required: ["flag"],
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const result = (await generateFromSchema({ schema, count: 5 })) as Array<{
|
|
132
|
-
flag: boolean;
|
|
133
|
-
}>;
|
|
134
|
-
|
|
135
|
-
expect(Array.isArray(result)).toBe(true);
|
|
136
|
-
expect(result).toHaveLength(5);
|
|
137
|
-
for (const item of result) {
|
|
138
|
-
expect(item.flag).toBe(true);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("non-object data passes through unchanged", async () => {
|
|
143
|
-
// A string schema should pass through postProcessGenerated without issues
|
|
144
|
-
const schema: JSONSchema7 = {
|
|
145
|
-
type: "string",
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const result = await generateFromSchema({ schema });
|
|
149
|
-
expect(typeof result).toBe("string");
|
|
150
|
-
});
|
|
151
|
-
});
|