@schmock/faker 2.3.0 → 2.4.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/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-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 +19 -4
- 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 +21 -7
- package/dist/constants.js +0 -8
- package/dist/field-mappings.js +0 -1114
- package/dist/field-name-matcher.js +0 -148
- package/dist/jsf-config.js +0 -117
- package/dist/overrides.js +0 -137
- package/dist/schema-enhancement.js +0 -104
- package/dist/test-utils.d.ts +0 -57
- package/dist/test-utils.d.ts.map +0 -1
- package/dist/test-utils.js +0 -284
- 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 -1148
- package/src/field-name-matcher.test.ts +0 -292
- package/src/field-name-matcher.ts +0 -187
- package/src/index.d.ts.map +0 -1
- package/src/index.test.ts +0 -1320
- package/src/index.ts +0 -185
- package/src/integration.test.ts +0 -634
- package/src/jsf-config.d.ts.map +0 -1
- package/src/jsf-config.test.ts +0 -65
- package/src/jsf-config.ts +0 -156
- 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 -179
- package/src/performance.test.ts +0 -441
- package/src/plugin-integration.test.ts +0 -575
- package/src/post-process.test.ts +0 -177
- package/src/real-world.test.ts +0 -636
- package/src/schema-enhancement.d.ts.map +0 -1
- package/src/schema-enhancement.test.ts +0 -222
- package/src/schema-enhancement.ts +0 -144
- package/src/steps/deterministic-seeds.steps.ts +0 -112
- package/src/steps/faker-plugin.steps.ts +0 -301
- package/src/test-utils.ts +0 -385
- package/src/validation.d.ts.map +0 -1
- package/src/validation.ts +0 -417
package/src/post-process.test.ts
DELETED
|
@@ -1,177 +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("uses the generation seed for a reproducible nullable distribution", async () => {
|
|
12
|
-
const nullableString: JSONSchema7 & { schmockNullable: boolean } = {
|
|
13
|
-
type: "string",
|
|
14
|
-
schmockNullable: true,
|
|
15
|
-
};
|
|
16
|
-
const schema: JSONSchema7 = {
|
|
17
|
-
type: "array",
|
|
18
|
-
items: {
|
|
19
|
-
type: "object",
|
|
20
|
-
properties: { value: nullableString },
|
|
21
|
-
required: ["value"],
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const first = await generateFromSchema({ schema, count: 200, seed: 42 });
|
|
26
|
-
const second = await generateFromSchema({ schema, count: 200, seed: 42 });
|
|
27
|
-
|
|
28
|
-
expect(first).toEqual(second);
|
|
29
|
-
if (!Array.isArray(first)) {
|
|
30
|
-
throw new Error("Expected generated nullable data to be an array");
|
|
31
|
-
}
|
|
32
|
-
const values = first.map((item) => {
|
|
33
|
-
if (typeof item !== "object" || item === null || !("value" in item)) {
|
|
34
|
-
throw new Error("Expected each nullable item to contain value");
|
|
35
|
-
}
|
|
36
|
-
return item.value;
|
|
37
|
-
});
|
|
38
|
-
expect(values.filter((value) => value === null)).toHaveLength(9);
|
|
39
|
-
expect(values.filter((value) => typeof value === "string")).toHaveLength(
|
|
40
|
-
191,
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("postProcessGenerated — schmockTrueProbability", () => {
|
|
46
|
-
it("uses the generation seed for deterministic weighted booleans", async () => {
|
|
47
|
-
const weightedBoolean: JSONSchema7 & {
|
|
48
|
-
schmockTrueProbability: number;
|
|
49
|
-
} = {
|
|
50
|
-
type: "boolean",
|
|
51
|
-
schmockTrueProbability: 0.5,
|
|
52
|
-
};
|
|
53
|
-
const schema: JSONSchema7 = {
|
|
54
|
-
type: "array",
|
|
55
|
-
items: {
|
|
56
|
-
type: "object",
|
|
57
|
-
properties: { flag: weightedBoolean },
|
|
58
|
-
required: ["flag"],
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const first = await generateFromSchema({ schema, count: 12, seed: 42 });
|
|
63
|
-
const second = await generateFromSchema({ schema, count: 12, seed: 42 });
|
|
64
|
-
|
|
65
|
-
expect(first).toEqual(second);
|
|
66
|
-
expect(Array.isArray(first)).toBe(true);
|
|
67
|
-
if (!Array.isArray(first)) {
|
|
68
|
-
throw new Error("Expected generated data to be an array");
|
|
69
|
-
}
|
|
70
|
-
const flags = first.flatMap((item) => {
|
|
71
|
-
if (typeof item !== "object" || item === null || !("flag" in item)) {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
return [item.flag];
|
|
75
|
-
});
|
|
76
|
-
expect(flags).toContain(true);
|
|
77
|
-
expect(flags).toContain(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("applies a reproducible weighted boolean distribution", async () => {
|
|
81
|
-
const weightedBoolean: JSONSchema7 & {
|
|
82
|
-
schmockTrueProbability: number;
|
|
83
|
-
} = {
|
|
84
|
-
type: "boolean",
|
|
85
|
-
schmockTrueProbability: 0.8,
|
|
86
|
-
};
|
|
87
|
-
const schema: JSONSchema7 = {
|
|
88
|
-
type: "array",
|
|
89
|
-
items: {
|
|
90
|
-
type: "object",
|
|
91
|
-
properties: { flag: weightedBoolean },
|
|
92
|
-
required: ["flag"],
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const first = await generateFromSchema({ schema, count: 200, seed: 42 });
|
|
97
|
-
const second = await generateFromSchema({ schema, count: 200, seed: 42 });
|
|
98
|
-
|
|
99
|
-
expect(first).toEqual(second);
|
|
100
|
-
if (!Array.isArray(first)) {
|
|
101
|
-
throw new Error("Expected generated weighted data to be an array");
|
|
102
|
-
}
|
|
103
|
-
const flags = first.map((item) => {
|
|
104
|
-
if (typeof item !== "object" || item === null || !("flag" in item)) {
|
|
105
|
-
throw new Error("Expected each weighted item to contain flag");
|
|
106
|
-
}
|
|
107
|
-
return item.flag;
|
|
108
|
-
});
|
|
109
|
-
expect(flags.filter((flag) => flag === true)).toHaveLength(162);
|
|
110
|
-
expect(flags.filter((flag) => flag === false)).toHaveLength(38);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe("postProcessGenerated — recursive processing", () => {
|
|
115
|
-
it("nested object properties are recursively processed", async () => {
|
|
116
|
-
const schema: JSONSchema7 = {
|
|
117
|
-
type: "object",
|
|
118
|
-
properties: {
|
|
119
|
-
outer: {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: {
|
|
122
|
-
inner: {
|
|
123
|
-
type: "boolean",
|
|
124
|
-
schmockTrueProbability: 1.0,
|
|
125
|
-
} as JSONSchema7 & { schmockTrueProbability: number },
|
|
126
|
-
},
|
|
127
|
-
required: ["inner"],
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
required: ["outer"],
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// With schmockTrueProbability = 1.0, every run should yield true
|
|
134
|
-
for (let i = 0; i < 10; i++) {
|
|
135
|
-
const result = (await generateFromSchema({ schema })) as {
|
|
136
|
-
outer: { inner: boolean };
|
|
137
|
-
};
|
|
138
|
-
expect(result.outer.inner).toBe(true);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("array items are recursively processed", async () => {
|
|
143
|
-
const schema: JSONSchema7 = {
|
|
144
|
-
type: "array",
|
|
145
|
-
items: {
|
|
146
|
-
type: "object",
|
|
147
|
-
properties: {
|
|
148
|
-
flag: {
|
|
149
|
-
type: "boolean",
|
|
150
|
-
schmockTrueProbability: 1.0,
|
|
151
|
-
} as JSONSchema7 & { schmockTrueProbability: number },
|
|
152
|
-
},
|
|
153
|
-
required: ["flag"],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const result = (await generateFromSchema({ schema, count: 5 })) as Array<{
|
|
158
|
-
flag: boolean;
|
|
159
|
-
}>;
|
|
160
|
-
|
|
161
|
-
expect(Array.isArray(result)).toBe(true);
|
|
162
|
-
expect(result).toHaveLength(5);
|
|
163
|
-
for (const item of result) {
|
|
164
|
-
expect(item.flag).toBe(true);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("non-object data passes through unchanged", async () => {
|
|
169
|
-
// A string schema should pass through postProcessGenerated without issues
|
|
170
|
-
const schema: JSONSchema7 = {
|
|
171
|
-
type: "string",
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const result = await generateFromSchema({ schema });
|
|
175
|
-
expect(typeof result).toBe("string");
|
|
176
|
-
});
|
|
177
|
-
});
|