3

I'm using running hardhat tests. When I add console logs to the test cases, nothing actually gets outputted to console. Why's that?

1
  • 1
    Hi! console.log should be outputting text to the console the tests are running in. Could you edit the question to post the output of your tests, and maybe a code block from the tests with a console.log in it?
    – Linum Labs
    Apr 25 '21 at 6:46
3

When people report this, 99% the time it means that they are running npx hardhat node in one terminal and npx hardhat test --network localhost in the other, and they expect to see the logs in the second terminal, but it's actually shown in the first one. This happens because the output of console.log is shown in the process where the Hardhat Network is running.

This doesn't happen when you run npx hardhat test (without a --network param), because that uses the in-process hardhat network. That is, the test task and the network run in the same process, and therefore the output is shown in the same terminal.

I have an explainer about this that goes more in-depth about what happens in these different scenarios, and others, under the hood.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.