Skip to content

🛠️ Repo: Mocha's integration tests fail locally, and then tests won't run at all afterward #5376

@jdmarshall

Description

@jdmarshall

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Trying to run 'npm run test' locally in order to possibly create a PR to fix another issue:

333 passing (2m)
1 pending
3 failing

...

And then all subsequent runs of the tests don't even start, even after an 'npm run clean'. For some reason nuking node_modules and starting over makes it work again.

Actual

  333 passing (2m)
  1 pending
  3 failing

  1) esm
       should throw an ERR_MODULE_NOT_FOUND and not ERR_REQUIRE_ESM if file imports a non-existing module:
     
expected '\n Exception during run: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js in a cycle. (from /Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js)\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1572:16)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at Module.require (node:internal/modules/cjs/loader:1298:19)\n    at require (node:internal/modules/helpers:182:18)\n    at exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:10:8)\n    at async exports.loadFilesAsync (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:21:688)\n    at async singleRun (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:55:25)\n    at async exports.handler (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:19:457) {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n'
to contain 'ERR_MODULE_NOT_FOUND'


 Exception during run: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js in a cycle. (from /Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)
    at Module._compile (node:internal/modules/cjs/loader:1511:5)
    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)
    at Module._extensions..js (node:internal/modules/cjs/loader:1572:16)
    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1096:12)
    at Module.require (node:internal/modules/cjs/loader:1298:19)
    at require (node:internal/modules/helpers:182:18)
    at exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:10:8)
    at async exports.loadFilesAsync (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:21:688)
    at async singleRun (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:55:25)
    at async exports.handler (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:19:457) {
  code: 'ERR_REQUIRE_CYCLE_MODULE'
}


  UnexpectedError: 
  expected '\n Exception during run: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js in a cycle. (from /Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js)\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1572:16)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at Module.require (node:internal/modules/cjs/loader:1298:19)\n    at require (node:internal/modules/helpers:182:18)\n    at exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:10:8)\n    at async exports.loadFilesAsync (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:21:688)\n    at async singleRun (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:55:25)\n    at async exports.handler (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:19:457) {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n'
  to contain 'ERR_MODULE_NOT_FOUND'
  
  
   Exception during run: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js in a cycle. (from /Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js)
      at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)
      at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)
      at Module._compile (node:internal/modules/cjs/loader:1511:5)
      at Module.replacementCompile (node_modules/append-transform/index.js:60:13)
      at Module._extensions..js (node:internal/modules/cjs/loader:1572:16)
      at Object.<anonymous> (node_modules/append-transform/index.js:64:4)
      at Module.load (node:internal/modules/cjs/loader:1275:32)
      at Module._load (node:internal/modules/cjs/loader:1096:12)
      at Module.require (node:internal/modules/cjs/loader:1298:19)
      at require (node:internal/modules/helpers:182:18)
      at exports.requireOrImport (lib/nodejs/esm-utils.js:10:8)
      at async exports.loadFilesAsync (lib/nodejs/esm-utils.js:21:688)
      at async singleRun (lib/cli/run-helpers.js:55:25)
      at async exports.handler (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:19:457) {
    code: 'ERR_REQUIRE_CYCLE_MODULE'
  }
  
  
      at Context.<anonymous> (test/integration/esm.spec.js:79:5)
      set UNEXPECTED_FULL_TRACE=true to see the full stack trace

  2) root hooks
       when mocha run in serial mode
         support ESM via .js extension w/o type=module
           should fail due to ambiguous file type
             with --no-experimental-detect-module:
     
expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
  expected
  {
    output: '\n✖ ERROR: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at cjsLoader (node:internal/modules/esm/translators:298:15)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:240:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:263:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)\n    at async formattedImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:2:577)\n    at async exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:7:1135)\n    at async exports.handleRequires (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:38:364)\n    at async /Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:18:41 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
    code: 1,
    args: [
      '/Users/jasonmarshall/Projects/cobbler/mocha/bin/mocha.js',
      '--require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js',
      '--no-experimental-detect-module',
      '--no-color',
      '--no-bail',
      '--no-parallel'
    ],
    command: '/Users/jasonmarshall/Projects/cobbler/mocha/bin/mocha.js --require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js --no-experimental-detect-module --no-color --no-bail --no-parallel'
  }
  to contain output /SyntaxError: Unexpected token/

  
  expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
    expected
    {
      output: '\n✖ ERROR: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at cjsLoader (node:internal/modules/esm/translators:298:15)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:240:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:263:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)\n    at async formattedImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:2:577)\n    at async exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:7:1135)\n    at async exports.handleRequires (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:38:364)\n    at async /Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:18:41 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
      code: 1,
      args: [
        '--require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js',
        '--no-experimental-detect-module',
        '--no-color',
        '--no-bail',
        '--no-parallel'
      ],
    }
    to contain output /SyntaxError: Unexpected token/
      at Array.forEach (<anonymous>)
  From previous event:
      at Context.<anonymous> (test/integration/plugins/root-hooks.spec.js:146:18)
      at callFn (lib/runnable.js:112:584)
      at Runnable.run (lib/runnable.js:112:57)
      at Runner.runTest (lib/runner.js:220:1054)
      at /Users/jasonmarshall/Projects/cobbler/mocha/lib/runner.js:248:654
      at next (lib/runner.js:197:422)
      at /Users/jasonmarshall/Projects/cobbler/mocha/lib/runner.js:197:809
      at next (lib/runner.js:185:579)
      at Immediate.<anonymous> (lib/runner.js:189:1253)
      at process.processImmediate (node:internal/timers:483:21)
      set UNEXPECTED_FULL_TRACE=true to see the full stack trace

  3) root hooks
       when mocha run in serial mode
         support ESM via .js extension w/o type=module
           should fail due to ambiguous file type
             with --experimental-detect-module:
     
expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
  expected
  {
    output: '\n✖ ERROR: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at cjsLoader (node:internal/modules/esm/translators:298:15)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:240:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:263:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)\n    at async formattedImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:2:577)\n    at async exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:7:1135)\n    at async exports.handleRequires (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:38:364)\n    at async /Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:18:41 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
    code: 1,
    args: [
      '/Users/jasonmarshall/Projects/cobbler/mocha/bin/mocha.js',
      '--require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js',
      '--experimental-detect-module',
      '--no-color',
      '--no-bail',
      '--no-parallel'
    ],
    command: '/Users/jasonmarshall/Projects/cobbler/mocha/bin/mocha.js --require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js --experimental-detect-module --no-color --no-bail --no-parallel'
  }
  to contain output /SyntaxError: Unexpected token/

  
  expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
    expected
    {
      output: '\n✖ ERROR: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:309:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1371:24)\n    at Module._compile (node:internal/modules/cjs/loader:1511:5)\n    at Module.replacementCompile (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)\n    at Object.<anonymous> (/Users/jasonmarshall/Projects/cobbler/mocha/node_modules/append-transform/index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1275:32)\n    at Module._load (node:internal/modules/cjs/loader:1096:12)\n    at cjsLoader (node:internal/modules/esm/translators:298:15)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:240:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:263:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)\n    at async formattedImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:2:577)\n    at async exports.requireOrImport (/Users/jasonmarshall/Projects/cobbler/mocha/lib/nodejs/esm-utils.js:7:1135)\n    at async exports.handleRequires (/Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run-helpers.js:38:364)\n    at async /Users/jasonmarshall/Projects/cobbler/mocha/lib/cli/run.js:18:41 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
      code: 1,
      args: [
        '--require=/Users/jasonmarshall/Projects/cobbler/mocha/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js',
        '--experimental-detect-module',
        '--no-color',
        '--no-bail',
        '--no-parallel'
      ],
    }
    to contain output /SyntaxError: Unexpected token/
      at Array.forEach (<anonymous>)
  From previous event:
      at Context.<anonymous> (test/integration/plugins/root-hooks.spec.js:166:18)
      at callFn (lib/runnable.js:112:584)
      at Runnable.run (lib/runnable.js:112:57)
      at Runner.runTest (lib/runner.js:220:1054)
      at /Users/jasonmarshall/Projects/cobbler/mocha/lib/runner.js:248:654
      at next (lib/runner.js:197:422)
      at /Users/jasonmarshall/Projects/cobbler/mocha/lib/runner.js:197:809
      at next (lib/runner.js:185:579)
      at Immediate.<anonymous> (lib/runner.js:189:1253)
      at process.processImmediate (node:internal/timers:483:21)
      set UNEXPECTED_FULL_TRACE=true to see the full stack trace



ERROR: "test-node:integration" exited with 3.
ERROR: "test-node" exited with 1.


npm run test

> [email protected] test
> run-s lint test-node test-browser


> [email protected] lint
> run-p lint:*


> [email protected] lint:installed-check
> installed-check --engine-check


> [email protected] lint:markdown
> markdownlint "*.md" "docs/**/*.md" ".github/*.md" "lib/**/*.md" "test/**/*.md" "example/**/*.md" -i CHANGELOG.md


> [email protected] lint:code
> eslint . "bin/*" --max-warnings 0


> [email protected] lint:knip
> knip --cache

Unused files (1)
lib/nodejs/worker.js
Configuration issues (1)
Unused item in ignoreDependencies: prettier
ERROR: "lint:knip" exited with 1.
ERROR: "lint" exited with 1.

Minimal, Reproducible Example

Clone the repo and run 'npm i' locally.

If there's something else I'm supposed to be doing, it's not in the developer documents.

Versions

11.6.0

v20.19.0, but also fails on 22

Additional Info

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions