Skip to content

tests not running when using import-in-the-middle with mocha #34

@pichlermarc

Description

@pichlermarc

It seems that when using import-in-the-middle with mocha, mocha exits without running tests as require.main === module evaluates to false when it's trying to determine if it is run directly from Node.js.

Expected Behavior

mocha runs tests even if IITM is used

Actual Behavior

mocha exists with 0, not running any tests

Steps to Reproduce the Problem

I've created a reproducer to illustrate that contains a more detailed description:
https://github.com/pichlermarc/esm-test

It contains two scripts, both attempt to run a single test that always fails, one with the IITM loader, and one without.

  1. git clone https://github.com/pichlermarc/esm-test
  2. npm install
  3. npm run test
    - this does not use the IITM hook, tests do run, and mocha exits with 1 (as expected)
  4. npm run test:iitm
    - this uses the IITM hook, tests do not run, and mocha exits with 0 (1 is expected)

Specifications

  • Version:
    • import-in-the-middle@1.4.2
    • mocha@10.2.0
    • Node.js v18.18.1
  • Platform: Ubuntu 22.04
  • Subsystem:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions