Skip to content

Commit 4c39dee

Browse files
committed
Fix for #1001
1 parent 6dd0d2c commit 4c39dee

File tree

3 files changed

+13
-53
lines changed

3 files changed

+13
-53
lines changed

lib/cli.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ internals.options = function () {
431431
'lint-fix': false,
432432
'lint-errors-threshold': 0,
433433
'lint-warnings-threshold': 0,
434-
'max-diff-length': 20 * 1024, // 20K should be more than most people want logged to their console. The diff algorithm becomes very slow for larger strings.
435434
paths: ['test'],
436435
reporter: 'console',
437436
retries: 5,
@@ -469,8 +468,8 @@ internals.options = function () {
469468
'coverage-path', 'coverage-all', 'coverage-flat', 'coverage-module', 'coverage-pattern',
470469
'default-plan-threshold', 'dry', 'environment', 'flat', 'globals', 'grep',
471470
'lint', 'lint-errors-threshold', 'lint-fix', 'lint-options', 'lint-warnings-threshold',
472-
'linter', 'max-diff-length', 'output', 'pattern', 'reporter', 'retries', 'seed', 'shuffle', 'silence',
473-
'silent-skips', 'sourcemaps', 'threshold', 'timeout', 'transform', 'types', 'types-test', 'verbose'];
471+
'linter', 'output', 'pattern', 'reporter', 'retries', 'seed', 'shuffle', 'silence', 'silent-skips',
472+
'sourcemaps', 'threshold', 'timeout', 'transform', 'types', 'types-test', 'typescript', 'verbose'];
474473

475474
for (let i = 0; i < keys.length; ++i) {
476475
if (argv.hasOwnProperty(keys[i]) && argv[keys[i]] !== undefined && argv[keys[i]] !== null) {

lib/reporters/console.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const SupportsColor = require('supports-color');
77

88

99
const internals = {
10-
width: 50
10+
width: 50,
11+
maxDiffLength: 20 * 1024 // 20Kb
1112
};
1213

1314

@@ -212,15 +213,12 @@ internals.Reporter.prototype.end = function (notebook) {
212213
let actual = internals.stringify(test.err.actual);
213214
let expected = internals.stringify(test.err.expected);
214215

215-
if (this.settings['max-diff-length'] > 0) {
216-
const maxLen = this.settings['max-diff-length'];
217-
if (actual.length > maxLen) {
218-
actual = actual.substr(0, maxLen) + '[truncated]';
219-
}
216+
if (actual.length > internals.maxDiffLength) {
217+
actual = actual.substr(0, internals.maxDiffLength) + '[truncated]';
218+
}
220219

221-
if (expected.length > maxLen) {
222-
expected = expected.substr(0, maxLen) + '[truncated]';
223-
}
220+
if (expected.length > internals.maxDiffLength) {
221+
expected = expected.substr(0, internals.maxDiffLength) + '[truncated]';
224222
}
225223

226224
output += ' ' + whiteRedBg('actual') + ' ' + blackGreenBg('expected') + '\n\n ';

test/reporters.js

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -362,51 +362,14 @@ describe('Reporter', () => {
362362

363363
script.test('works', () => {
364364

365-
expect({ a: 1 }).to.equal({ b: 1 });
365+
const long = new Array(21 * 1024).fill('a');
366+
expect({ a: long }).to.equal({ b: long });
366367
});
367368
});
368369

369-
const { code, output } = await Lab.report(script, { reporter: 'console', colors: false, output: false, 'max-diff-length': 8 });
370-
expect(code).to.equal(1);
371-
expect(output).to.contain('ab: 1[truncated]');
372-
expect(output).to.contain('1 of 1 tests failed');
373-
expect(output).to.contain('Test duration:');
374-
expect(output).to.contain('Leaks: No issues');
375-
});
376-
377-
it('does not truncate if max diff length is set to 0', async () => {
378-
379-
const script = Lab.script();
380-
script.experiment('test', () => {
381-
382-
script.test('works', () => {
383-
384-
expect({ a: 1 }).to.equal({ b: 1 });
385-
});
386-
});
387-
388-
const { code, output } = await Lab.report(script, { reporter: 'console', colors: false, output: false, 'max-diff-length': 0 });
389-
expect(code).to.equal(1);
390-
expect(output).to.contain('ab: 1\n');
391-
expect(output).to.contain('1 of 1 tests failed');
392-
expect(output).to.contain('Test duration:');
393-
expect(output).to.contain('Leaks: No issues');
394-
});
395-
396-
it('does not truncate if diff length less than the maximum', async () => {
397-
398-
const script = Lab.script();
399-
script.experiment('test', () => {
400-
401-
script.test('works', () => {
402-
403-
expect({ a: 1 }).to.equal({ b: 1 });
404-
});
405-
});
406-
407-
const { code, output } = await Lab.report(script, { reporter: 'console', colors: false, output: false, 'max-diff-length': 10 * 1024 });
370+
const { code, output } = await Lab.report(script, { reporter: 'console', colors: false, output: false });
408371
expect(code).to.equal(1);
409-
expect(output).to.not.contain('[truncated]');
372+
expect(output).to.contain('[truncated]');
410373
expect(output).to.contain('1 of 1 tests failed');
411374
expect(output).to.contain('Test duration:');
412375
expect(output).to.contain('Leaks: No issues');

0 commit comments

Comments
 (0)