microsoft / microsoft/nodejstools

Mocha require seems to be ignored for test discovery

Open
#2,235 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.8k
Forks
355
PR merge metrics
No merged PRs in 30d

Description

I have a Mocha setup that uses module-alias and esm to load modules using ES6 import. That works fine when running that through npm using:
mocha --require module-alias/register --require esm "test/**/*.js"

I've added a mocha.json with the same require:
"require": [ "module-alias/register", "esm" ]

From the test log I can see that this configuration is read correctly, but the test discovery fails with an error message indicating that the ES6 import is not understood:

Test discovery error: mytest.js:1
(function (exports, require, module, __filename, __dirname) { import { assert } from 'chai';
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
[...]

This is the exact same error I get when running through npm without --require esm.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the npm command and the equivalent mocha.json containing module-alias/register and esm. Compare how the two configurations are applied during test discovery, then verify that ES6 imports are accepted during discovery as they are when running Mocha directly.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.