MCPcopy Index your code
hub / github.com/glideapps/quicktype / compareJsonFileToJson

Function compareJsonFileToJson

test/utils.ts:153–191  ·  view source on GitHub ↗
(args: ComparisonArgs)

Source from the content-addressed store, hash-verified

151};
152
153export function compareJsonFileToJson(args: ComparisonArgs) {
154 debug(args);
155
156 const { expectedFile, strict } = args;
157 const given: any = args.given;
158
159 const jsonString = given.file
160 ? callAndReportFailure("Could not read JSON output file", () =>
161 fs.readFileSync(given.file, "utf8")
162 )
163 : callAndReportFailure(
164 "Could not run command for JSON output",
165 () => exec(given.command).stdout
166 );
167
168 const givenJSON = callAndReportFailure("Could not parse output JSON", () =>
169 JSON.parse(jsonString)
170 );
171 const expectedJSON = callAndReportFailure(
172 "Could not read or parse expected JSON file",
173 () => JSON.parse(fs.readFileSync(expectedFile, "utf8"))
174 );
175
176 const allowMissingNull = !!args.allowMissingNull;
177 let jsonAreEqual = strict
178 ? callAndReportFailure("Failed to strictly compare objects", () =>
179 strictDeepEquals(givenJSON, expectedJSON)
180 )
181 : callAndReportFailure("Failed to compare objects.", () =>
182 deepEquals(expectedJSON, givenJSON, allowMissingNull)
183 );
184
185 if (!jsonAreEqual) {
186 failWith("Error: Output is not equivalent to input.", {
187 expectedFile,
188 given
189 });
190 }
191}

Callers 4

testMethod · 0.90
testMethod · 0.90
testMethod · 0.90
testMethod · 0.90

Calls 5

debugFunction · 0.85
callAndReportFailureFunction · 0.85
deepEqualsFunction · 0.85
failWithFunction · 0.85
execFunction · 0.70

Tested by 4

testMethod · 0.72
testMethod · 0.72
testMethod · 0.72
testMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…