Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
deferRecord(hash, options) {
const descriptor = concordance.describe(options.expected, concordanceOptions);
const snapshot = concordance.serialize(descriptor);
const entry = formatEntry(options.label, descriptor);
return () => { // Must be called in order!
this.hasChanges = true;
let snapshots = this.snapshotsByHash.get(hash);
if (!snapshots) {
snapshots = [];
this.snapshotsByHash.set(hash, snapshots);
}
if (options.index > snapshots.length) {
throw new RangeError(`Cannot record snapshot ${options.index} for ${JSON.stringify(options.belongsTo)}, exceeds expected index of ${snapshots.length}`);
}
if (options.index < snapshots.length) {
// Babel's default of 'development' if it's empty.
const envName = process.env.BABEL_ENV || ('NODE_ENV' in process.env ? process.env.NODE_ENV : 'test') || 'development';
// Prepare inputs for caching seeds. Compute a seed based on the Node.js
// version and the project directory. Dependency hashes may vary based on the
// Node.js version, e.g. with the @ava/stage-4 Babel preset. Certain plugins
// and presets are provided as absolute paths, which wouldn't necessarily
// be valid if the project directory changes. Also include `envName`, so
// options can be cached even if users change BABEL_ENV or NODE_ENV between
// runs.
const seedInputs = [
process.versions.node,
packageHash.sync(require.resolve('../package.json')),
projectDir,
envName,
concordance.serialize(concordance.describe(userOptions))
];
const partialCacheKey = md5Hex(seedInputs);
const pluginAndPresetHashes = new Map();
const ensureStage4 = wantsStage4(userOptions, projectDir, {experiments});
const containsStage4 = makeValueChecker('../stage-4');
const containsTransformTestFiles = makeValueChecker('@ava/babel-preset-transform-test-files');
const loadOptions = filename => {
const partialTestConfig = babel.loadPartialConfig({
babelrc: false,
babelrcRoots: [projectDir],
configFile: false,
sourceMaps: true,
...userOptions && userOptions.testOptions,