diff --git a/README.md b/README.md index 0f6d4128..222634c2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/plugins/hardhat.plugin.js b/plugins/hardhat.plugin.js index d91509d4..b4f0a53f 100644 --- a/plugins/hardhat.plugin.js +++ b/plugins/hardhat.plugin.js @@ -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);