hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Running A Single Test File, Hardhat Finds No Tests

Open JimLynchCodes opened this issue 3 years ago • 2 comments

Suppose I have some files in my project under the test folder

test/ - MyToken.test.js - MyHelperFunction.test.js - Foo.test.js

If I run npx hardhat test then it runs all the tests in all the files and everything works.

If I run npx hardhat test ./test/nonexistent.file.js then I can an error:

Error: Cannot find module '/Users/jim/Git-Projects/AppleTreeNFT-Smart-Contracts/packages/hardhat/test/nonexistent.file.js'

If I run npx hardhat test ./test/Foo.test.js then I get this output:

·------------------------|---------------------------|-------------|----------------------------·
|  Solc version: 0.8.13  ·  Optimizer enabled: true  ·  Runs: 200  ·  Block limit: 6718946 gas  │
·························|···························|·············|·····························
|  Methods                                                                                      │
··············|··········|·············|·············|·············|·············|···············
|  Contract   ·  Method  ·  Min        ·  Max        ·  Avg        ·  # calls    ·  usd (avg)   │
·-------------|----------|-------------|-------------|-------------|-------------|--------------·

  0 passing (248ms)

When running any file I always get this "0 passing" message.

This is a bug because it should be running the tests in the file but it incorrectly runs nothing.

node v14.19.1

JimLynchCodes avatar Aug 04 '22 17:08 JimLynchCodes

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: 7c4aa311-0df3-4aa7-b6cc-d59df814676d

github-actions[bot] avatar Aug 04 '22 17:08 github-actions[bot]

@JimLynchCodes this works for me. Can you tell me more about your setup? Are you on Windows? Which version of Hardhat are you using?

Also, just in case: can you try doing npx hardhat test test/Foo.test.js (that is, without the ./)?

fvictorio avatar Aug 08 '22 08:08 fvictorio

Closing for lack of more information.

fvictorio avatar Aug 22 '22 09:08 fvictorio