From b04709cab8ede0ed2b1bda55fd6ac56618e3a01c Mon Sep 17 00:00:00 2001 From: Grant Cheadle Date: Mon, 4 Mar 2024 15:33:13 -0800 Subject: [PATCH] fixes --- lib/cli/run-option-metadata.js | 1 - lib/reporters/base.js | 2 +- test/reporters/base.spec.js | 39 +++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index f38387a695..492608fbdd 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -78,7 +78,6 @@ exports.aliases = { ignore: ['exclude'], invert: ['i'], jobs: ['j'], - jsonStringifyWhitespace: ['jsw'], 'no-colors': ['C'], 'node-option': ['n'], parallel: ['p'], diff --git a/lib/reporters/base.js b/lib/reporters/base.js index d9f028273b..bad9fa22b7 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -295,7 +295,7 @@ exports.list = function (failures) { // indented test title var testTitle = ''; - // Incase test is an AggregateError object when recursively listing errors + if (test instanceof AggregateError) { test.titlePath().forEach(function (str, index) { if (index !== 0) { diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.js index d3c87702b0..d17c678f27 100644 --- a/test/reporters/base.spec.js +++ b/test/reporters/base.spec.js @@ -517,7 +517,44 @@ describe('Base reporter', function () { var errOut = stdout.join('\n').trim(); - expect(errOut, 'to contain', ' Error: 1', 'Error: 2'); + // Handle removing system's specific error callStack + errOut = errOut + .split('\n') + .filter(line => !line.trim().startsWith('at ')) + .join('\n') + .replace(/\n/g, ''); + + var expectedFormat = `1) : ${aggErr.name}: ${aggErr.message} 1) : ${err1.name}: ${err1.message} 2) : ${err2.name}: ${err2.message}`; + + expect(errOut, 'to equal', expectedFormat); + }); + + it('should handle Aggregate Error Objects with 0 errors properly', function () { + var aggErr = new AggregateError([], ' 0 errors'); + + var test = makeTest(aggErr); + list([test]); + + var errOut = stdout.join('\n').trim(); + + var expectedFormat = aggErr.name + ': ' + aggErr.message; + + expect(errOut, 'to contain', expectedFormat); + }); + + it('should handle non-Error types properly', function () { + var nonError = {name: 'NotAnError', message: 'This is not an error object'}; + var aggErr = new AggregateError([nonError]); + + var test = makeTest(aggErr); + list([test]); + + assert.strictEqual(aggErr.errors.length, 1, 'Should contain one error'); + assert.strictEqual( + aggErr.errors[0], + nonError, + 'The non-Error object should be preserved in the errors array' + ); }); });