From 9b3d5d21a0f6810c2ef73b9fa1d2bc3ea7d01929 Mon Sep 17 00:00:00 2001 From: khoaHyh Date: Tue, 6 Feb 2024 22:59:05 -0500 Subject: [PATCH] refactor: log warning and remove call stack --- bin/mocha.js | 0 lib/cli/collect-files.js | 7 +++++-- test/integration/options/file.spec.js | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) mode change 100644 => 100755 bin/mocha.js diff --git a/bin/mocha.js b/bin/mocha.js old mode 100644 new mode 100755 diff --git a/lib/cli/collect-files.js b/lib/cli/collect-files.js index 91293811f5..f33b496994 100644 --- a/lib/cli/collect-files.js +++ b/lib/cli/collect-files.js @@ -60,8 +60,11 @@ module.exports = ({ require.resolve(fileAbsolutePath); } catch (err) { // this error doesn't bubble up to the middleware like how - // --require handles it so we have to do it here - console.error(`\n${symbols.error} ${ansi.red('ERROR:')}`, err); + // --require handles it so we log a warning here and exit + const warningMessage = ansi.yellow( + `${symbols.warning} Warning: Cannot find test file "${file}" at the path "${fileAbsolutePath}"` + ); + console.warn(`${warningMessage}\n`); process.exit(1); } }); diff --git a/test/integration/options/file.spec.js b/test/integration/options/file.spec.js index 15a9c83b22..3ce3f45dfa 100644 --- a/test/integration/options/file.spec.js +++ b/test/integration/options/file.spec.js @@ -67,7 +67,7 @@ describe('--file', function () { }); }); - it('should throw an ERR_MODULE_NOT_FOUND if a nonexistent file is specified', function (done) { + it('should log a warning if a nonexistent file is specified', function (done) { runMocha( 'esm/type-module/test-that-imports-non-existing-module.fixture.js', ['--file'], @@ -76,7 +76,7 @@ describe('--file', function () { return done(err); } - expect(res.output, 'to contain', 'ERR_MODULE_NOT_FOUND').and( + expect(res.output, 'to contain', 'Warning: Cannot find test file').and( 'to contain', 'test-that-imports-non-existing-module' );