MCPcopy
hub / github.com/webpack/webpack / expectSnapshotState

Function expectSnapshotState

test/FileSystemInfo.unittest.js:232–294  ·  test/FileSystemInfo.unittest.js::expectSnapshotState
(
		/** @type {IFs} */ fs,
		/** @type {Snapshot | null | undefined} */ snapshot,
		/** @type {boolean} */ expected,
		/** @type {(err?: Error | null) => void} */ callback
	)

Source from the content-addressed store, hash-verified

230 };
231
232 const expectSnapshotState = (
233 /** @type {IFs} */ fs,
234 /** @type {Snapshot | null | undefined} */ snapshot,
235 /** @type {boolean} */ expected,
236 /** @type {(err?: Error | null) => void} */ callback
237 ) => {
238 const fsInfo = createFsInfo(fs);
239 const details = (/** @type {unknown} */ snapshot) => `${
240 /** @type {string[]} */ (
241 /** @type {Record<string, unknown>} */ (fsInfo).logs
242 ).join(class="st">"\n")
243 }
244${util.inspect(snapshot, false, Infinity, true)}`;
245 fsInfo.checkSnapshotValid(
246 /** @type {Snapshot} */ (snapshot),
247 (err, valid) => {
248 if (err) return callback(err);
249 if (valid !== expected) {
250 return callback(
251 new Error(`Expected snapshot to be ${
252 expected ? class="st">"valid" : class="st">"invalid"
253 } but it is ${valid ? class="st">"valid" : class="st">"invalid"}:
254${details(snapshot)}`)
255 );
256 }
257 class="cm">// Another try to check if direct caching works
258 fsInfo.checkSnapshotValid(
259 /** @type {Snapshot} */ (snapshot),
260 (err, valid) => {
261 if (err) return callback(err);
262 if (valid !== expected) {
263 return callback(
264 new Error(`Expected snapshot lead to the same result when directly cached:
265${details(snapshot)}`)
266 );
267 }
268 class="cm">// Another try to check if indirect caching works
269 fsInfo.checkSnapshotValid(
270 /** @type {Snapshot} */ (
271 /** @type {unknown} */ (
272 clone(
273 /** @type {Record<string, unknown>} */ (
274 /** @type {unknown} */ (snapshot)
275 )
276 )
277 )
278 ),
279 (err, valid) => {
280 if (err) return callback(err);
281 if (valid !== expected) {
282 return callback(
283 new Error(`Expected snapshot lead to the same result when indirectly cached:
284${details(snapshot)}`)
285 );
286 }
287 callback();
288 }
289 );

Callers 2

expectSnapshotsStateFunction · 0.85

Calls 5

createFsInfoFunction · 0.85
detailsFunction · 0.85
cloneFunction · 0.85
checkSnapshotValidMethod · 0.80
callbackFunction · 0.70

Tested by

no test coverage detected