Skip to content

Commit

Permalink
chore: fix golden_file_test accept
Browse files Browse the repository at this point in the history
When the diff was very large, the output was truncated so you couldn't see the command to accept new golden
  • Loading branch information
alexeagle committed Oct 2, 2019
1 parent 0312800 commit e08ac31
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/golden_file_test/bin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const unidiff = require('unidiff');

function main(args) {
const [mode, golden_no_debug, golden_debug, actual] = args;
Expand All @@ -15,9 +14,13 @@ function main(args) {
fs.writeFileSync(require.resolve(golden), actualContents);
console.error(`Replaced ${path.join(process.cwd(), golden)}`);
} else if (mode === '--verify') {
const unidiff = require('unidiff');
// Generated does not match golden
const diff = unidiff.diffLines(goldenContents, actualContents);
const prettyDiff = unidiff.formatLines(diff, {aname: golden, bname: actual});
let prettyDiff = unidiff.formatLines(diff, {aname: golden, bname: actual});
if (prettyDiff.length > 5000) {
prettyDiff = prettyDiff.substr(0, 5000) + '/n...elided...';
}
throw new Error(`Actual output doesn't match golden file:
${prettyDiff}
Expand Down

0 comments on commit e08ac31

Please sign in to comment.