Skip to content

Mocha test subtask resolution in Hardhat 3 #7758

@BlockChain-Man

Description

@BlockChain-Man

Version of Hardhat

3.0.17

What happened?

No contracts to compile
Running Mocha tests
An unexpected error occurred:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'H:\Blockchain\JS\hard\nodejs' imported from H:\Blockchain\JS\hard\node_modules\mocha\lib\nodejs\esm-utils.js
at finalizeResolution (node:internal/modules/esm/resolve:274:11)
at moduleResolve (node:internal/modules/esm/resolve:864:10)
at defaultResolve (node:internal/modules/esm/resolve:990:11)
at nextResolve (node:internal/modules/esm/hooks:785:28)
at resolveBase (file:///H:/Blockchain/js/hard/node_modules/tsx/dist/esm/index.mjs?1765132150489:2:3744)
at resolveDirectory (file:///H:/Blockchain/js/hard/node_modules/tsx/dist/esm/index.mjs?1765132150489:2:4243)
at resolveTsPaths (file:///H:/Blockchain/js/hard/node_modules/tsx/dist/esm/index.mjs?1765132150489:2 at resolve (file:///H:/Blockchain/js/hard/node_modules/tsx/dist/esm/index.mjs?1765132150489:2:5361)
at nextResolve (node:internal/modules/esm/hooks:785:28)
at AsyncLoaderHooksOnLoaderHookWorker.resolve (node:internal/modules/esm/hooks:271:30) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///H:/Blockchain/JS/hard/nodejs'
}

Minimal reproduction steps

npx hardhat test nodejs --coverage

Proposed solution

Resolve the parameter of the test task as follows:

npx hardhat test PARAM
  • Process PARAM as a file (as implemented now) in case PARAM refers to a valid file path
  • Resolve PARAM as a subtask in case it is not a valid file path
    • Throw the following error in case the subtask PARAM is not valid
      Error HHE416: Unrecognized subtask "PARAM" for the task "test"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions