How to use concordance - 10 common examples

To help you get started, we’ve selected a few concordance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avajs / ava / lib / snapshot-manager.js View on Github external
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) {
github avajs / ava / lib / babel-pipeline.js View on Github external
// 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,
github avajs / ava / test / reporters / format-serialized-error.js View on Github external
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();
});
github avajs / ava / test / reporters / format-serialized-error.js View on Github external
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();
});
github hildjj / node-cbor / test / implementation_matrix.js View on Github external
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
}
github hildjj / node-cbor / test / implementation_matrix.js View on Github external
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
}
github testdouble / ought / lib / diff.js View on Github external
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
  )
}
github netlify / cli / src / utils / addons / diffs / index.js View on Github external
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)
}
github otissv / remodule / node_modules / ava / lib / assert.js View on Github external
function formatWithLabel(label, value) {
	return formatDescriptorWithLabel(label, concordance.describe(value, concordanceOptions));
}
github avajs / ava / lib / assert.js View on Github external
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)]
				}));
			}
		});

concordance

Compare, format, diff and serialize any JavaScript value

ISC
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis