From b6fd9bc518f1e92d1f1dea22f5fedc0e73acd2ed Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 4 Jan 2019 23:26:12 +0000 Subject: [PATCH 1/6] errors dont show mutiple messages --- lib/cli/run-helpers.js | 11 ++++------- test/integration/glob.spec.js | 18 +++--------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 95d1c2fc08..c7575751f5 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -137,14 +137,14 @@ exports.handleFiles = ({ spec = [] } = {}) => { let files = []; - const errors = []; + const missingMessages = []; spec.forEach(arg => { let newFiles; try { newFiles = utils.lookupFiles(arg, extension, recursive); } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { - errors.push(err.message); + missingMessages.push(err.message); return; } @@ -164,14 +164,11 @@ exports.handleFiles = ({ }); if (!files.length) { - // print messages as an error - errors.forEach(message => { - console.error(ansi.red(`Error: ${message}`)); - }); + console.error(ansi.red('Error: No test files found')); process.exit(1); } else { // print messages as an warning - errors.forEach(message => { + missingMessages.forEach(message => { console.warn(ansi.yellow(`Warning: ${message}`)); }); } diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index da1f5f35c6..3995339bf4 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -25,11 +25,7 @@ describe('globbing', function() { testGlob.shouldFail( './*-none.js', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern "./*-none.js"' - ); + expect(results.stderr, 'to contain', 'Error: No test files found'); }, done ); @@ -74,11 +70,7 @@ describe('globbing', function() { testGlob.shouldFail( '"./*-none.js"', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern "./*-none.js"' - ); + expect(results.stderr, 'to contain', 'Error: No test files found'); }, done ); @@ -122,11 +114,7 @@ describe('globbing', function() { testGlob.shouldFail( '"./**/*-none.js"', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern "./**/*-none.js"' - ); + expect(results.stderr, 'to contain', 'Error: No test files found'); }, done ); From 7be247e36023abf595be85f58dfec1444d366cdc Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 4 Jan 2019 23:43:20 +0000 Subject: [PATCH 2/6] give message if only 1 file missing --- lib/cli/run-helpers.js | 7 ++++++- test/integration/glob.spec.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index c7575751f5..94cad55384 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -164,7 +164,12 @@ exports.handleFiles = ({ }); if (!files.length) { - console.error(ansi.red('Error: No test files found')); + if (missingMessages.length === 1) { + // give message details when only 1 missing file + console.error(ansi.red(`Error: ${missingMessages[0]}`)); + } else { + console.error(ansi.red('Error: No test files found')); + } process.exit(1); } else { // print messages as an warning diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 3995339bf4..fc3f7bda9e 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -24,6 +24,20 @@ describe('globbing', function() { it('should not find a non-matching pattern', function(done) { testGlob.shouldFail( './*-none.js', + function(results) { + expect( + results.stderr, + 'to contain', + 'Error: Cannot find any files matching pattern' + ); + }, + done + ); + }); + + it('should handle multiple non-matching patterns', function(done) { + testGlob.shouldFail( + './*-none.js ./*-none-twice.js', function(results) { expect(results.stderr, 'to contain', 'Error: No test files found'); }, @@ -69,6 +83,20 @@ describe('globbing', function() { it('should not find a non-matching pattern', function(done) { testGlob.shouldFail( '"./*-none.js"', + function(results) { + expect( + results.stderr, + 'to contain', + 'Error: Cannot find any files matching pattern' + ); + }, + done + ); + }); + + it('should handle multiple non-matching patterns', function(done) { + testGlob.shouldFail( + '"./*-none.js" "./*-none-twice.js"', function(results) { expect(results.stderr, 'to contain', 'Error: No test files found'); }, @@ -114,7 +142,11 @@ describe('globbing', function() { testGlob.shouldFail( '"./**/*-none.js"', function(results) { - expect(results.stderr, 'to contain', 'Error: No test files found'); + expect( + results.stderr, + 'to contain', + 'Error: Cannot find any files matching pattern' + ); }, done ); From 5d49ff31cf4b34a1c72cd82a6a3009271c9274b6 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Fri, 4 Jan 2019 23:52:03 +0000 Subject: [PATCH 3/6] add unit test --- lib/cli/run-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 94cad55384..f78329d3eb 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -165,7 +165,7 @@ exports.handleFiles = ({ if (!files.length) { if (missingMessages.length === 1) { - // give message details when only 1 missing file + // give full message details when only 1 file is missing console.error(ansi.red(`Error: ${missingMessages[0]}`)); } else { console.error(ansi.red('Error: No test files found')); From fcedb8f546c4d07485ce0595f5062e3370d14e1b Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Tue, 8 Jan 2019 17:06:55 +0000 Subject: [PATCH 4/6] add pattern for error and message for warning --- lib/cli/run-helpers.js | 20 ++++++++++---------- test/integration/glob.spec.js | 18 +++--------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index f78329d3eb..db50cc3d90 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -137,14 +137,14 @@ exports.handleFiles = ({ spec = [] } = {}) => { let files = []; - const missingMessages = []; + const unmatched = []; spec.forEach(arg => { let newFiles; try { newFiles = utils.lookupFiles(arg, extension, recursive); } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { - missingMessages.push(err.message); + unmatched.push({message: err.message, pattern: err.pattern}); return; } @@ -164,17 +164,17 @@ exports.handleFiles = ({ }); if (!files.length) { - if (missingMessages.length === 1) { - // give full message details when only 1 file is missing - console.error(ansi.red(`Error: ${missingMessages[0]}`)); - } else { - console.error(ansi.red('Error: No test files found')); - } + // give full message details when only 1 file is missing + const noneFoundMsg = + unmatched.length === 1 + ? `Error: No test files found: ${unmatched[0].pattern}` + : 'Error: No test files found'; + console.error(ansi.red(noneFoundMsg)); process.exit(1); } else { // print messages as an warning - missingMessages.forEach(message => { - console.warn(ansi.yellow(`Warning: ${message}`)); + unmatched.forEach(warning => { + console.warn(ansi.yellow(`Warning: ${warning.message}`)); }); } diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index fc3f7bda9e..0f767887af 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -25,11 +25,7 @@ describe('globbing', function() { testGlob.shouldFail( './*-none.js', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern' - ); + expect(results.stderr, 'to contain', 'Error: No test files found:'); }, done ); @@ -84,11 +80,7 @@ describe('globbing', function() { testGlob.shouldFail( '"./*-none.js"', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern' - ); + expect(results.stderr, 'to contain', 'Error: No test files found:'); }, done ); @@ -142,11 +134,7 @@ describe('globbing', function() { testGlob.shouldFail( '"./**/*-none.js"', function(results) { - expect( - results.stderr, - 'to contain', - 'Error: Cannot find any files matching pattern' - ); + expect(results.stderr, 'to contain', 'Error: No test files found:'); }, done ); From 5ad9a14fb9ab1ab06bd74b6a0aaa4bc79d1e4288 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Tue, 8 Jan 2019 17:10:49 +0000 Subject: [PATCH 5/6] re-add pattern back to tests which need it --- test/integration/glob.spec.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 0f767887af..240184801e 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -25,7 +25,11 @@ describe('globbing', function() { testGlob.shouldFail( './*-none.js', function(results) { - expect(results.stderr, 'to contain', 'Error: No test files found:'); + expect( + results.stderr, + 'to contain', + 'Error: No test files found: ./*-none.js' + ); }, done ); @@ -80,7 +84,11 @@ describe('globbing', function() { testGlob.shouldFail( '"./*-none.js"', function(results) { - expect(results.stderr, 'to contain', 'Error: No test files found:'); + expect( + results.stderr, + 'to contain', + 'Error: No test files found: ./*-none.js' + ); }, done ); @@ -134,7 +142,11 @@ describe('globbing', function() { testGlob.shouldFail( '"./**/*-none.js"', function(results) { - expect(results.stderr, 'to contain', 'Error: No test files found:'); + expect( + results.stderr, + 'to contain', + 'Error: No test files found: ./**/*-none.js' + ); }, done ); From 2acf1bfc3e10e1229f5f8d744b3245fbfa1cb537 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Tue, 8 Jan 2019 19:35:26 +0000 Subject: [PATCH 6/6] stringify to print escaped characters raw --- lib/cli/run-helpers.js | 2 +- test/integration/glob.spec.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index db50cc3d90..df53117fec 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -167,7 +167,7 @@ exports.handleFiles = ({ // give full message details when only 1 file is missing const noneFoundMsg = unmatched.length === 1 - ? `Error: No test files found: ${unmatched[0].pattern}` + ? `Error: No test files found: ${JSON.stringify(unmatched[0].pattern)}` // stringify to print escaped characters raw : 'Error: No test files found'; console.error(ansi.red(noneFoundMsg)); process.exit(1); diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 240184801e..4284320aa7 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -28,7 +28,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'Error: No test files found: ./*-none.js' + 'Error: No test files found: "./*-none.js"' ); }, done @@ -40,6 +40,7 @@ describe('globbing', function() { './*-none.js ./*-none-twice.js', function(results) { expect(results.stderr, 'to contain', 'Error: No test files found'); + expect(results.stderr, 'not to contain', '*-none'); }, done ); @@ -87,7 +88,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'Error: No test files found: ./*-none.js' + 'Error: No test files found: "./*-none.js"' ); }, done @@ -145,7 +146,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'Error: No test files found: ./**/*-none.js' + 'Error: No test files found: "./**/*-none.js"' ); }, done