How to use dir-compare - 10 common examples

To help you get started, we’ve selected a few dir-compare 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 NekR / offline-plugin / tests / legacy / compare.js View on Github external
} else {
    log(chalk.inverse('Comparing: ' + path.basename(testDir)));
  }

  log('');

  var expectedFolder = path.join(testDir, '__expected', 'webpack' + webpackVersion.split('.')[0]);
  var outputFolder = path.join(testDir, '__output');

  try {
    fs.accessSync(expectedFolder);
  } catch (e) {
    return Promise.resolve();
  }

  var res = dircompare.compareSync(
    expectedFolder,
    outputFolder,
    options
  );

  if (isFix) {
    res.diffSet.forEach(function (entry) {
      var name1 = entry.name1 || '';
      var name2 = entry.name2 || '';

      if (entry.state === 'equal') {
        // Do nothing
      } else if (entry.state === 'left') {
        // Remove file from expected
        del.sync(path.join(entry.path1, name1));
        logFile(name1, chalk.red('[missing]'));
github electrode-io / electrode-native / system-tests / utils / sameDirContent.js View on Github external
module.exports = function(
  pathA,
  pathB,
  {
    excludeFilter, // File/directory name exclude filter. Comma separated minimatch patterns.
  } = {}
) {
  let result = true
  const directoriesDiff = dircompare.compareSync(pathA, pathB, {
    compareContent: true,
    excludeFilter,
  })
  for (const diff of directoriesDiff.diffSet) {
    if (diff.state === 'distinct') {
      console.log('A difference in content was found !')
      console.log(JSON.stringify(diff))
      let diffLine = jsdiff.diffLines(
        fs.readFileSync(path.join(diff.path1, diff.name1)).toString(),
        fs.readFileSync(path.join(diff.path2, diff.name2)).toString()
      )
      diffLine.forEach(part => {
        let color = part.added ? 'green' : part.removed ? 'red' : 'grey'
        process.stderr.write(part.value[color])
      })
      result = false
github AndyOGo / node-sync-glob / test / helpers.js View on Github external
export const compare = (done, source, target, options) => (event, data) => {
  if (event) {
    if (Array.isArray(data) && data.length === 2
      && typeof data[0] === 'string' && typeof data[1] === 'string') {
      // eslint-disable-next-line no-param-reassign
      [source, target] = data
    }

    const res = dirCompare.compareSync(source, target, {
      ...options,
      compareSize: true,
      compareContent: true,
    })

    expect(res.differences).toBe(0)
    expect(res.differencesFiles).toBe(0)
    expect(res.distinctFiles).toBe(0)
    expect(res.differencesDirs).toBe(0)
    expect(res.distinctDirs).toBe(0)

    if (done) {
      done()
    }
  }
}
github davidmerfield / Blot / tests / util / compareDir.js View on Github external
module.exports = function(path1, path2, options, callback) {

  // Required
  options.compareSize = true;
  options.compareContent = true;

  // Git does not copy across datestamps but would be nice
  // options.compareDate = true;

  dircompare
    .compare(path1, path2, options)
    .then(function(res) {
      if (!res.differences) return callback();

      var message = [
        path1 + "<>" + path2 + " has " + res.differences + " differences"
      ];

      res.diffSet.forEach(function(entry) {
        if (entry.state === "equal") return;

        var state = {
          left: "->",
          right: "<-",
          distinct: "<>"
        }[entry.state];
github Gottwik / Enduro / libs / juicebox / juice_diff.js View on Github external
juice_diff.prototype.diff = function (path1, path2) {

	var store_compare_result
	return dircompare.compare(path1, path2)
		.then((compare_result) => {

			store_compare_result = compare_result

			// filter out ds_store files
			_.remove(compare_result.diffSet, function (file) {
				return (file.name1 == '.DS_Store' || file.name2 == '.DS_Store')
			})

			var abstract_cms_files = []
			compare_result.diffSet.forEach((item) => {
				abstract_cms_files.push(abstract_diff_item(item))
			})

			return Promise.all(abstract_cms_files)
		})
github flowup / api-client-generator / src / diff-tests.tests.ts View on Github external
sourceFile: `${reference.refDir}/swagger.${reference.swaggerFileExt}`,
    outputPath: reference.genDir,
    skipModuleExport: reference.skipIndex,
    splitPathTags: reference.tags ? reference.tags.split(',') : []
  })
    .catch((err: Error) => console.error(`Error has occurred while generating api client for ${reference.name}`, err));

  const {
    same,
    equal,
    distinct,
    differences,
    left,
    right,
    diffSet,
  } = await compare(`${reference.refDir}/api`, reference.genDir, COMPARE_OPTIONS);

  if (!same) {
    let result = ' Output should be the same, but there are differences.\n\n';
    result += `differences: ${differences}\n\n`;
    result += `equal: ${equal}\n`;
    result += `distinct: ${distinct}\n`;
    result += `left: ${left}\n`;
    result += `right: ${right}\n`;
    result += '[ reference dir ]               [ test dir ]\n';

    diffSet.forEach(({name1, name2, state, type1, type2}: DiffSet) => {
      if (stateSymbols[state] !== stateSymbols.equal) {
        result += `(${type1}) ${name1}  ${stateSymbols[state]}  ${name2} (${type2})\n`;
      }
    });
github flowup / api-client-generator / src / tests.ts View on Github external
const testReturnValues = await Promise.all(testReferences.map(async (reference) => {
    console.info(`Running test for ${reference.name}`);

    const refDir = `${__dirname}/../tests/${reference.name}`;
    const genDir = `${testsOutDir}/${reference.name}`;

    await generateAPIClient({
      sourceFile: `${refDir}/swagger.${reference.swaggerFileExt}`,
      outputPath: genDir,
      skipModuleExport: reference.skipIndex,
      splitPathTags: reference.tags ? reference.tags.split(',') : []
    })
      .catch((err: Error) => console.error(`Error has occurred while generating api client for ${reference.name}`, err));

    const {same, equal, distinct, differences, left, right, diffSet} = await compare(`${refDir}/api`, genDir, compareOptions);

    if (!same) {
      console.info(Colors.Red, `Test for ${reference.name} has failed\n`, Colors.Reset);
      console.group(`Stats for ${reference.name}`);
      console.info(`equal: ${equal}`);
      console.info(`distinct: ${distinct}`);
      console.info(`left: ${left}`);
      console.info(`right: ${right}`);
      console.info(`differences: ${differences}\n`);

      console.info('[ reference dir ]         [ test dir ]');
      diffSet.forEach(({name1, name2, state, type1, type2}: DiffSet) => {
        if (stateSymbols[state] !== stateSymbols.equal) {
          console.info(`(${type1}) ${name1}  ${stateSymbols[state]}  ${name2} (${type2})`);
        }
      });
github jondot / hygen / src / __tests__ / metaverse.spec.ts View on Github external
}
      }
      const res = await runner(cmd, config)
      res.actions.forEach(a => {
        a.timing = -1
        a.subject = a.subject.replace(/.*hygen\/src/, '')
      })
      expect(res).toMatchSnapshot(cmd.join(' '))
    }
    const givenDir = path.join(metaDir, 'given')
    const expectedDir = path.join(metaDir, 'expected')
    console.log('after', {
      [givenDir]: fs.readdirSync(givenDir),
      [expectedDir]: fs.readdirSync(expectedDir),
    })
    const res = dirCompare.compareSync(givenDir, expectedDir, opts)
    res.diffSet = res.diffSet.filter(d => d.state !== 'equal')
    if (!res.same) {
      console.log(res)
    }
    expect(res.same).toEqual(true)
  })
github DefinitelyTyped / tsd / test / nspec / cases-spec.js View on Github external
function assertDiff(expected, actual) {
    var res = dircompare.compareSync(expected, actual, {
        compareSize: true,
        compareContent: true
    });
    res.diffSet.forEach(function (entry) {
        var state = {
            'equal': '==',
            'left': '->',
            'right': '<-',
            'distinct': '<>'
        }[entry.state];
        var name1 = entry.name1 ? entry.name1 : '';
        var name2 = entry.name2 ? entry.name2 : '';
        var space = '                                ';
        console.log('        - ' + pad(space, name1 + '(' + entry.type1.cyan + ') ', true)
            + state + ' ' + pad(space, name2 + '(' + entry.type2.cyan + ')', true));
        if (entry.state === 'distinct') {
github brunocodutra / webapp-webpack-plugin / test / index.js View on Github external
test('should generate the expected default result', async t => {
  const stats = await webpack(baseWebpackConfig(new WebappWebpackPlugin({
    logo: LOGO
  })));
  const outputPath = stats.compilation.compiler.outputPath;
  const expected = path.resolve(FIXTURES, 'expected/default');
  const compareResult = await dircompare.compare(outputPath, expected, compareOptions);
  const diff = compareResult.diffSet.filter(({state}) => state !== 'equal').map(({name1, name2}) => `${name1}${name2}`);
  t.deepEqual(diff, []);
});

dir-compare

Node JS directory compare

MIT
Latest version published 7 months ago

Package Health Score

70 / 100
Full package analysis