Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
}
},
};
traverse(fileNode, {
enter: path => {
const visitor = Visitors[path.node.type];
if (visitor != null) {
visitor(path, state, this._matchers);
}
},
});
// NOTE if no projectConfig is given the default resolver will be used
const snapshotResolver = buildSnapshotResolver(this._projectConfig || {});
const snapshotPath = snapshotResolver.resolveSnapshotPath(filePath);
const snapshots = utils.getSnapshotData(snapshotPath, 'none').data;
let lastParent = null;
let count = 1;
return state.found.map(snapshotNode => {
const parents = snapshotNode.parents.filter(isValidParent);
const innerAssertion = parents[parents.length - 1];
if (lastParent !== innerAssertion) {
lastParent = innerAssertion;
count = 1;
}
const result = {
content: undefined,
dispatch({
name: 'include_test_location_in_result',
});
}
// Jest tests snapshotSerializers in order preceding built-in serializers.
// Therefore, add in reverse because the last added is the first tested.
config.snapshotSerializers
.concat()
.reverse()
.forEach(path => {
addSerializer(localRequire(path));
});
const {expand, updateSnapshot} = globalConfig;
const snapshotResolver = buildSnapshotResolver(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse,
getPrettier,
updateSnapshot,
});
setState({snapshotState, testPath});
addEventHandler(handleSnapshotStateAfterRetry(snapshotState));
// Return it back to the outer scope (test runner outside the VM).
return {globals, snapshotState};
};
let currentTestName = null;
for (let i = lineno - 1; i >= 0; i -= 1) {
const line = lines[i];
const trimmed = line.trimLeft();
if (trimmed.startsWith('it(') || trimmed.startsWith('it.only(')) {
[, currentTestName] = line.match(/it.*\((.*),/);
break;
}
}
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,