Skip to content

Aggregate --gas-stats output for multi-runner test execution#8036

Merged
schaable merged 7 commits intomainfrom
aggregate-gas-stats-output
Mar 12, 2026
Merged

Aggregate --gas-stats output for multi-runner test execution#8036
schaable merged 7 commits intomainfrom
aggregate-gas-stats-output

Conversation

@schaable
Copy link
Copy Markdown
Member

@schaable schaable commented Mar 6, 2026

When multiple test runners (e.g., solidity + nodejs) are used together, --gas-stats now aggregates gas measurements across all runners and prints a single consolidated table at the end, instead of printing separate tables per runner. Follows the same approach used in the coverage plugin.

Also includes minor refactors to encapsulate internal _coverage/_gasAnalytics property access behind helper functions (getCoverageManager, setCoverageManager, getGasAnalyticsManager, setGasAnalyticsManager).

This PR can be reviewed one commit at a time.

Closes #7500

@schaable schaable self-assigned this Mar 6, 2026
@schaable schaable added no docs needed This PR doesn't require links to documentation no peer bump needed labels Mar 6, 2026
Copilot AI review requested due to automatic review settings March 6, 2026 22:27
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: 126259a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Hardhat’s --gas-stats behavior to produce a single consolidated gas statistics report when multiple test runners are executed in one test invocation, matching the aggregation approach already used by the coverage plugin. It also refactors internal access to _coverage and _gasAnalytics to go through helper functions instead of direct property access.

Changes:

  • Aggregate gas measurements across multiple runner IDs and print one final gas stats table at the end of the overall test task.
  • Add enableReport/disableReport support to gas analytics to suppress per-runner reporting during multi-runner execution.
  • Introduce/get/use get*/set* helper functions for coverage and gas analytics managers across tasks and hook handlers; update tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Disables per-runner reporting and prints a single aggregated coverage + gas stats report at the end using runner IDs.
v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts Routes coverage collection and gas measurement recording through the new manager helpers.
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts Adds report enable/disable gating and supports loading measurements from multiple runner IDs.
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/types.ts Extends the manager interface with enableReport() / disableReport().
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/helpers.ts Adds getGasAnalyticsManager/setGasAnalyticsManager helpers and keeps backward-compatible exported test hooks.
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/hook-handlers/test.ts Uses getGasAnalyticsManager instead of direct _gasAnalytics access.
v-next/hardhat/src/internal/builtin-plugins/gas-analytics/hook-handlers/hre.ts Uses setGasAnalyticsManager to attach the manager to the HRE.
v-next/hardhat/src/internal/builtin-plugins/coverage/helpers.ts Adds getCoverageManager/setCoverageManager helpers and keeps backward-compatible exported test hooks.
v-next/hardhat/src/internal/builtin-plugins/coverage/hook-handlers/test.ts Uses getCoverageManager instead of direct _coverage access.
v-next/hardhat/src/internal/builtin-plugins/coverage/hook-handlers/solidity.ts Uses getCoverageManager when recording metadata during Solidity preprocessing.
v-next/hardhat/src/internal/builtin-plugins/coverage/hook-handlers/hre.ts Uses setCoverageManager to attach the manager to the HRE.
v-next/hardhat/test/internal/builtin-plugins/gas-analytics/gas-analytics-manager.ts Adds tests for multi-ID loading and aggregated reporting behavior (including report enable/disable).
v-next/hardhat/test/internal/builtin-plugins/coverage/coverage-manager.ts Updates tests to use setCoverageManager helper and adjusts console suppression/comment formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@schaable schaable changed the title Aggregate gas stats output for multi-runner test execution Aggregate --gas-stats output for multi-runner test execution Mar 9, 2026
@schaable schaable added no docs needed This PR doesn't require links to documentation and removed no docs needed This PR doesn't require links to documentation labels Mar 9, 2026
@schaable schaable force-pushed the aggregate-gas-stats-output branch from eec7cb6 to e62d33c Compare March 12, 2026 13:05
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a tiny comment, but LGTM

Copilot AI review requested due to automatic review settings March 12, 2026 13:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 14 changed files in this pull request and generated 2 comments.

Comment thread v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Outdated
@schaable schaable force-pushed the aggregate-gas-stats-output branch from 8ab302f to 126259a Compare March 12, 2026 16:51
@schaable schaable added this pull request to the merge queue Mar 12, 2026
Merged via the queue into main with commit 6df1f18 Mar 12, 2026
213 checks passed
@schaable schaable deleted the aggregate-gas-stats-output branch March 12, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine gas statistics from different test runners

3 participants