Skip to content

Commit d89dbaf

Browse files
fix: swallow more require errors from *ts files (#5498)
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
1 parent 8649f39 commit d89dbaf

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

.github/DEVELOPMENT.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ If you are having trouble, don't be afraid to [ask for help](./CONTRIBUTING.md#
1616
- Do not use `yarn install` or `pnpm install`.
1717
- Some optional dependencies may fail; you can safely ignore these unless you are trying to build the documentation.
1818
- If you're sick of seeing the failures, run `npm install --ignore-scripts`.
19+
20+
## Tests
21+
22+
Running tests via `npm test` should work on any operating system with any supported version of Node. If they don't, please file an issue or contact us in [our Discord](https://discord.gg/KeDn2uXhER).
23+
24+
Running tests this way runs all tests in a "covered" state. That is, they're run through Istanbul's `nyc` command. This pre-loads some modules for coverage reporting and can change the behavior in niche situations around Node's loader system.
25+
26+
Tests with `@bare` in their name should also be run in an uncovered or "bare" state, that is, directly through `node bin/mocha.js` and not through `nyc`. `npm test` and our CI handles this with `test-node-integration:bare`. See [issue 5361 (comment)](https://github.com/mochajs/mocha/issues/5361#issuecomment-3368708708) for details.

.github/workflows/mocha.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- interfaces
3838
- unit
3939
- integration
40+
- integration:bare
4041
- jsapi
4142
- requires
4243
- reporters
@@ -63,6 +64,8 @@ jobs:
6364
include:
6465
- test-part: jsapi
6566
coverage: false
67+
- test-part: integration:bare
68+
coverage: false
6669
with:
6770
os: 'ubuntu-latest,windows-latest'
6871
# We pin exact versions here per https://github.com/mochajs/mocha/issues/5052

lib/nodejs/esm-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const requireModule = async (file, esmDecorator) => {
106106
// What we actually care about is the original require() error.
107107
// See: https://github.com/mochajs/mocha/issues/5393
108108
if (
109-
/\.(cts|mts|ts)$/.test(file) ||
109+
/\.(cts|mts|ts)$/.test(file) &&
110110
importErr.code === 'ERR_UNKNOWN_FILE_EXTENSION'
111111
) {
112112
throw requireErr;

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
"test-coverage-generate": "nyc report --reporter=lcov --reporter=text",
7474
"test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js",
7575
"test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only",
76+
"test-node-run:bare": "node bin/mocha.js --grep @bare",
7677
"test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"",
78+
"test-node:integration:bare": "run-s clean build && npm run -s test-node-run:bare -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"",
7779
"test-node:integration:watch": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/options/watch.spec.js\"",
7880
"test-node:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec",
7981
"test-node:interfaces:exports": "npm run -s test-node-run -- --ui exports test/interfaces/exports.spec",

test/integration/esm.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('esm', function () {
8282
);
8383
});
8484

85-
it('should throw an ERR_MODULE_NOT_FOUND and not ERR_REQUIRE_ESM if file imports a non-existing module with a loader', async function () {
85+
it('should throw an ERR_MODULE_NOT_FOUND and not ERR_REQUIRE_ESM if file imports a non-existing module with a loader @bare', async function () {
8686
const fixture =
8787
'esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts';
8888

0 commit comments

Comments
 (0)