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,
test('print statements after values', t => {
const err = {
statements: [
['actual.a[0]', concordance.format(1)]
],
values: [
{
label: 'Actual:',
formatted: concordance.format([1, 2, 3])
}
]
};
t.is(formatSerializedError(err).formatted, [
'Actual:',
`${err.values[0].formatted}`,
`actual.a[0]\n${chalk.grey('=>')} ${concordance.format(1)}`
].join('\n\n'));
t.end();
});
test('print multiple values', t => {
const err = {
statements: [],
values: [
{
label: 'Actual:',
formatted: concordance.format([1, 2, 3])
},
{
label: 'Expected:',
formatted: concordance.format({a: 1, b: 2, c: 3})
}
]
};
t.is(formatSerializedError(err).formatted, [
'Actual:\n',
`${err.values[0].formatted}\n`,
'Expected:\n',
err.values[1].formatted
].join('\n'));
t.end();
});
function deepEqual(actual, expected) {
const ret = concordance.compare(actual, expected)
if (!ret.pass) {
const a = ret.actual || concordance.describe(actual)
const e = ret.expected || concordance.describe(expected)
return false
}
return true
}
function deepEqual(actual, expected) {
const ret = concordance.compare(actual, expected)
if (!ret.pass) {
const a = ret.actual || concordance.describe(actual)
const e = ret.expected || concordance.describe(expected)
return false
}
return true
}
module.exports = function diff (actual, expected, color) {
const { defaultOptions, diffOptions } = concordanceOptions(color)
const result = concordance.compare(actual, expected, defaultOptions)
return concordance.diffDescriptors(
result.actual || concordance.describe(actual, defaultOptions),
result.expected || concordance.describe(expected, defaultOptions),
diffOptions
)
}
module.exports = function diffValues(actual, expected) {
const result = concordance.compare(actual, expected, concordanceOptions)
if (result.pass) {
return null
}
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions)
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions)
return formatDescriptorDiff(actualDescriptor, expectedDescriptor)
}
function formatWithLabel(label, value) {
return formatDescriptorWithLabel(label, concordance.describe(value, concordanceOptions));
}
this.deepEqual = withSkip((actual, expected, message) => {
if (!checkMessage('deepEqual', message)) {
return;
}
const result = concordance.compare(actual, expected, concordanceOptions);
if (result.pass) {
pass();
} else {
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions);
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions);
fail(new AssertionError({
assertion: 'deepEqual',
message,
raw: {actual, expected},
values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
}));
}
});