Skip to content

Commit

Permalink
Add variable on global HH env identifying solidity-coverage task (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Jan 17, 2022
1 parent 5b7eb34 commit 81c6b50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ const CoverageAPI = require('solidity-coverage/api');

[Documentation available here][28].

## Detecting solidity-coverage from another task

If you're writing another plugin or task, it can be helpful to detect whether coverage is running or not.
The coverage plugin sets a boolean variable on the globally injected hardhat environment object for this purpose.

```
hre.__SOLIDITY_COVERAGE_RUNNING === true
```

## FAQ

Common problems & questions:
Expand Down
3 changes: 3 additions & 0 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ task("coverage", "Generates a code coverage report for tests")
instrumentedSources = {};
measureCoverage = true;

// Set a variable on the environment so other tasks can detect if this task is executing
env.__SOLIDITY_COVERAGE_RUNNING = true;

try {
config = nomiclabsUtils.normalizeConfig(env.config, args);
ui = new PluginUI(config.logger.log);
Expand Down

0 comments on commit 81c6b50

Please sign in to comment.