Skip to content

Commit

Permalink
refactor: log warning and remove call stack
Browse files Browse the repository at this point in the history
  • Loading branch information
khoaHyh committed Feb 7, 2024
1 parent b6d6dc2 commit 9b3d5d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Empty file modified bin/mocha.js
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions lib/cli/collect-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/integration/options/file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'
);
Expand Down

0 comments on commit 9b3d5d2

Please sign in to comment.