Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const absoluteSnapshotFile = getAbsolutePathToSnapshot(this.testPath, snapshotFile);
// store the common state to re-use it in "afterAll" hook.
commonSnapshotState = this.snapshotState;
let snapshotState = snapshotsStateMap.get(absoluteSnapshotFile);
if (!snapshotState) {
snapshotState = new SnapshotState(absoluteSnapshotFile, {
updateSnapshot: commonSnapshotState._updateSnapshot,
snapshotPath: absoluteSnapshotFile,
});
snapshotsStateMap.set(absoluteSnapshotFile, snapshotState);
}
const newThis = Object.assign({}, this, { snapshotState });
const patchedToMatchSnapshot = toMatchSnapshot.bind(newThis);
return patchedToMatchSnapshot(received, testName);
}
function matchSnapshot(actual: string, testFile: string, testTitle: string) {
const snapshotState = new SnapshotState(testFile, {
updateSnapshot: process.env.SNAPSHOT_UPDATE ? 'all' : 'new',
});
const matcher = toMatchSnapshot.bind({
snapshotState,
currentTestName: testTitle,
});
const result = matcher(actual);
snapshotState.save();
return result;
}
if (currentTestName === null) {
throw new Error('Can not find current test name');
}
let { snapshotState } = runner.snapshotContexts.get(filename) || {};
if (!snapshotState) {
const snapshotResolver = buildSnapshotResolver({
rootDir: process.cwd(),
});
const snapshotPath = snapshotResolver.resolveSnapshotPath(filename);
snapshotState = new SnapshotState(snapshotPath, {
updateSnapshot: runner.argv.updateSnapshot ? 'all' : 'new',
});
runner.snapshotContexts.set(filename, { currentTestName, snapshotState });
}
const matcher = toMatchSnapshot.bind({
snapshotState,
currentTestName,
});
const result = matcher(this._obj);
this.assert(
result.pass,
result.message,
result.message,
result.expected,
result.report,
);
};
};