Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} 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]'));
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
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()
}
}
}
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];
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)
})
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`;
}
});
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})`);
}
});
}
}
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)
})
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') {
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, []);
});