From db722d0c6df02914e946254b2393a71d1c8a932c Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 16:30:18 +0000 Subject: [PATCH 1/7] error and exit, dont warn --- lib/cli/run-helpers.js | 4 ++-- lib/utils.js | 2 +- test/integration/glob.spec.js | 33 +++++++++------------------------ 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 5212d386db..06624f6c59 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -144,8 +144,8 @@ exports.handleFiles = ({ newFiles = utils.lookupFiles(arg, extension, recursive); } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { - console.warn('Warning: %s: %O', err.message, err.pattern); - return; + console.error(ansi.red(`${symbols.error} ${err.message}`)); + process.exit(1); } throw err; diff --git a/lib/utils.js b/lib/utils.js index f2f2af4145..c6d42ba9a5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -520,7 +520,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) { files = glob.sync(filepath); if (!files.length) { throw createNoFilesMatchPatternError( - 'cannot find any files matching pattern "' + filepath + '"', + 'Cannot find any files matching pattern "' + filepath + '"', filepath ); } diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 6aa7563bf5..31f435ed96 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', - 'cannot find any files matching pattern "./*-none.js"' + '✖ Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -36,18 +36,13 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldSucceed( + testGlob.shouldFail( './*.js ./*-none.js', function(results) { - expect( - results.stdout, - 'to contain', - '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' - ); expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + '✖ Cannot find any files matching pattern' ); }, done @@ -77,7 +72,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + '✖ Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -85,18 +80,13 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldSucceed( + testGlob.shouldFail( '"./*.js" "./*-none.js"', function(results) { - expect( - results.stdout, - 'to contain', - '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' - ); expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + '✖ Cannot find any files matching pattern' ); }, done @@ -125,7 +115,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + '✖ Cannot find any files matching pattern "./**/*-none.js"' ); }, done @@ -133,18 +123,13 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldSucceed( + testGlob.shouldFail( '"./**/*.js" "./**/*-none.js"', function(results) { - expect( - results.stdout, - 'to contain', - '["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,' - ); expect( results.stderr, 'to contain', - 'cannot find any files matching pattern' + '✖ Cannot find any files matching pattern' ); }, done From 96c3b1598fd1f921fcb6d7264e8269279549273a Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 16:59:08 +0000 Subject: [PATCH 2/7] return after error dont exit yet --- lib/cli/run-helpers.js | 2 +- test/integration/glob.spec.js | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 06624f6c59..2b90111669 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -145,7 +145,7 @@ exports.handleFiles = ({ } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { console.error(ansi.red(`${symbols.error} ${err.message}`)); - process.exit(1); + return; } throw err; diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 31f435ed96..0f70dd59b6 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -36,9 +36,14 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldFail( + testGlob.shouldSucceed( './*.js ./*-none.js', function(results) { + expect( + results.stdout, + 'to contain', + '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' + ); expect( results.stderr, 'to contain', @@ -80,9 +85,14 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldFail( + testGlob.shouldSucceed( '"./*.js" "./*-none.js"', function(results) { + expect( + results.stdout, + 'to contain', + '["end",{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,' + ); expect( results.stderr, 'to contain', @@ -123,9 +133,14 @@ describe('globbing', function() { }); it('should handle both matching and non-matching patterns in the same command', function(done) { - testGlob.shouldFail( + testGlob.shouldSucceed( '"./**/*.js" "./**/*-none.js"', function(results) { + expect( + results.stdout, + 'to contain', + '["end",{"suites":2,"tests":2,"passes":2,"pending":0,"failures":0,' + ); expect( results.stderr, 'to contain', From c4651cb783351cf8a5c1eadd8deb8715c76cd872 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 17:51:30 +0000 Subject: [PATCH 3/7] remove superflous message --- 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 2b90111669..f56fe29e1a 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -164,7 +164,7 @@ exports.handleFiles = ({ }); if (!files.length) { - console.error(ansi.red(`${symbols.error} No test files found`)); + // should have printed messags about missing tests already process.exit(1); } From 54bfedd0152327dd2cae19c096a0f1dd0ae3e57c Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 18:09:16 +0000 Subject: [PATCH 4/7] update glob tests --- 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 f56fe29e1a..7dc78e2fd9 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -164,7 +164,7 @@ exports.handleFiles = ({ }); if (!files.length) { - // should have printed messags about missing tests already + // should have printed message about missing tests already process.exit(1); } From 964f3638e0e8df6cb4e07c21bfb607f61941ceeb Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 18:36:30 +0000 Subject: [PATCH 5/7] update message --- 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 7dc78e2fd9..be9a3fcb18 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -164,7 +164,7 @@ exports.handleFiles = ({ }); if (!files.length) { - // should have printed message about missing tests already + // prints message about each individual missing file already process.exit(1); } From afc429e8315b2115ba37b1f1b9991589a351647d Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 19:06:04 +0000 Subject: [PATCH 6/7] use errors only if no tests found --- lib/cli/run-helpers.js | 13 +++++++++++-- test/integration/glob.spec.js | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index be9a3fcb18..76453c834b 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -138,13 +138,14 @@ exports.handleFiles = ({ spec = [] } = {}) => { let files = []; + let errors = []; spec.forEach(arg => { let newFiles; try { newFiles = utils.lookupFiles(arg, extension, recursive); } catch (err) { if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') { - console.error(ansi.red(`${symbols.error} ${err.message}`)); + errors.push(err.message); return; } @@ -164,8 +165,16 @@ exports.handleFiles = ({ }); if (!files.length) { - // prints message about each individual missing file already + // print messages as an error + errors.forEach(message => { + console.error(ansi.red(`${symbols.error} ${message}`)); + }); process.exit(1); + } else { + // print messages as an warning + errors.forEach(message => { + console.warn(`Warning: ${message}`); + }); } const fileArgs = file.map(filepath => path.resolve(filepath)); diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index 0f70dd59b6..fe0d05532e 100644 --- a/test/integration/glob.spec.js +++ b/test/integration/glob.spec.js @@ -47,7 +47,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - '✖ Cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done @@ -96,7 +96,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - '✖ Cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done @@ -144,7 +144,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - '✖ Cannot find any files matching pattern' + 'Warning: Cannot find any files matching pattern' ); }, done From 475d81c86531581c93fcd1141d82a5b6cbc98c29 Mon Sep 17 00:00:00 2001 From: Craig Taub Date: Thu, 3 Jan 2019 21:35:57 +0000 Subject: [PATCH 7/7] dont use error symbol. --- lib/cli/run-helpers.js | 7 +++---- test/integration/glob.spec.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 76453c834b..95d1c2fc08 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -14,7 +14,6 @@ const path = require('path'); const utils = require('../utils'); const minimatch = require('minimatch'); const ansi = require('ansi-colors'); -const symbols = require('log-symbols'); const cwd = (exports.cwd = process.cwd()); @@ -138,7 +137,7 @@ exports.handleFiles = ({ spec = [] } = {}) => { let files = []; - let errors = []; + const errors = []; spec.forEach(arg => { let newFiles; try { @@ -167,13 +166,13 @@ exports.handleFiles = ({ if (!files.length) { // print messages as an error errors.forEach(message => { - console.error(ansi.red(`${symbols.error} ${message}`)); + console.error(ansi.red(`Error: ${message}`)); }); process.exit(1); } else { // print messages as an warning errors.forEach(message => { - console.warn(`Warning: ${message}`); + console.warn(ansi.yellow(`Warning: ${message}`)); }); } diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.js index fe0d05532e..da1f5f35c6 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', - '✖ Cannot find any files matching pattern "./*-none.js"' + 'Error: Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -77,7 +77,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - '✖ Cannot find any files matching pattern "./*-none.js"' + 'Error: Cannot find any files matching pattern "./*-none.js"' ); }, done @@ -125,7 +125,7 @@ describe('globbing', function() { expect( results.stderr, 'to contain', - '✖ Cannot find any files matching pattern "./**/*-none.js"' + 'Error: Cannot find any files matching pattern "./**/*-none.js"' ); }, done