Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests can't be run programmatically more than once #1720

Closed
fvictorio opened this issue Jul 23, 2021 · 4 comments · Fixed by #2140
Closed

Tests can't be run programmatically more than once #1720

fvictorio opened this issue Jul 23, 2021 · 4 comments · Fixed by #2140
Assignees
Labels
type:bug Something isn't working

Comments

@fvictorio
Copy link
Member

Reproduction steps:

  1. Create the sample project

  2. Create a script like this:

    const hre = require("hardhat");
    
    async function main() {
      await hre.run("test")
      await hre.run("test")
    }
    
    main()
      .then(() => process.exit(0))
      .catch(error => {
        console.error(error);
        process.exit(1);
      });
  3. Run hh run script.js

Expected result: Tests should be run twice.

Actual result: the second run doesn't find any tests:


  Greeter
Deploying a Greeter with greeting: Hello, world!
Changing greeting from 'Hello, world!' to 'Hola, mundo!'
    ✓ Should return the new greeting once it's changed (782ms)


  1 passing (785ms)



  0 passing (0ms)

This seems like a "mocha caching something" thing.

@fvictorio fvictorio added type:bug Something isn't working package:hardhat-core labels Jul 23, 2021
@alcuadrado
Copy link
Member

This seems like a "mocha caching something" thing.

It's mocha loading the test files with require, so they only get interpreted once.

@ghost
Copy link

ghost commented Jul 29, 2021

I found same issue closed on mocha repo #2783. can be helpful.

@kanej kanej self-assigned this Dec 6, 2021
kanej added a commit that referenced this issue Dec 8, 2021
This is a mocha caching and cleanup issue addressed here: mochajs/mocha#2783.

Relates to #1720
@kanej kanej mentioned this issue Dec 8, 2021
3 tasks
@kanej kanej linked a pull request Dec 8, 2021 that will close this issue
3 tasks
kanej added a commit that referenced this issue Dec 10, 2021
This is a mocha caching and cleanup issue addressed here: mochajs/mocha#2783.

Multiple runs of the test task within a hardhat script are now enabled. The resolution is `mocha.dispose` at the end of a run to clear up state.

The mocha dispose method was added in mocha@7.2.0 but the @types/mocha doesn't reflect it till `9.0.0`. This commit:

* bumps mocha as a dep in hardhat-core to 7.2.0 to be explicit
* bumps mocha as a dev-dep everywhere else to 7.2.0 for consistency in our local dev environment
* bumps @types/mocha to 9 in dev-deps in all packages to allow use of dispose and consistency across packages - no code changes are required to support this. Note that the sample typescript project already provides a default @types/mocha on version 9.0.0

Relates to #1720
kanej added a commit that referenced this issue Dec 15, 2021
Fix reruns of `test` in scripts. This is a mocha caching and cleanup issue addressed here: mochajs/mocha#2783.

Multiple runs of the test task within a hardhat script are now enabled. The resolution is `mocha.dispose` at the end of a run to clear up state.

The mocha dispose method was added in mocha@7.2.0 but the @types/mocha doesn't reflect it till `9.0.0`. This commit:

* bumps mocha as a dep in hardhat-core to 7.2.0 to be explicit
* bumps mocha as a dev-dep everywhere else to 7.2.0 for consistency in our local dev environment
* bumps @types/mocha to 9 in dev-deps in all packages to allow use of dispose and consistency across packages - no code changes are required to support this. Note that the sample typescript project already provides a default @types/mocha on version 9.0.0

Relates to #1720
@fvictorio
Copy link
Member Author

Reopening so we can close it when this is released.

@fvictorio
Copy link
Member Author

Fixed in hardhat@2.8.1.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants