Skip to content

feat: return typed Result from test runner and telemetry task actions#8015

Merged
schaable merged 6 commits intomainfrom
task-result-actions
Mar 5, 2026
Merged

feat: return typed Result from test runner and telemetry task actions#8015
schaable merged 6 commits intomainfrom
task-result-actions

Conversation

@schaable
Copy link
Copy Markdown
Member

Update test runner (solidity, node, mocha) and telemetry task actions to return Result instead of setting process.exitCode. Define a shared TestSummary type and use isResult with type guards in the parent test task to aggregate results without type assertions.

This should be reviewed after #8012.

@schaable schaable self-assigned this Feb 28, 2026
@schaable schaable added the no docs needed This PR doesn't require links to documentation label Feb 28, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 28, 2026

🦋 Changeset detected

Latest commit: ed00780

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

This PR includes changesets to release 3 packages
Name Type
@nomicfoundation/hardhat-mocha Patch
@nomicfoundation/hardhat-node-test-runner Patch
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

Migrates built-in test runners (solidity, nodejs, mocha) and the telemetry task action to return the new typed Result (from #8012) instead of mutating process.exitCode, and introduces a shared TestSummary type so the parent test task can aggregate results via type guards.

Changes:

  • Add shared TestSummary type and switch test runner task actions to return Result<TestSummary, TestSummary>.
  • Update the parent test task to aggregate subtask results using isResult + type guards and return a Result itself.
  • Update related tests, peer bump metadata, and add a changeset documenting the new public types/helpers.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
v-next/hardhat/src/types/test.ts Introduces the shared TestSummary type for test runner payloads.
v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Aggregates subtask results using Result and returns a Result from the parent test task.
v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts Returns Result<TestSummary, TestSummary> instead of setting process.exitCode.
v-next/hardhat/src/internal/builtin-plugins/telemetry/task-action.ts Returns Result instead of setting process.exitCode for invalid flag combinations.
v-next/hardhat/test/internal/builtin-plugins/solidity-test/task-action.ts Updates tests to assert on Result.success rather than process.exitCode.
v-next/hardhat-node-test-runner/src/task-action.ts Returns Result<TestSummary, TestSummary> and uses successResult/errorResult.
v-next/hardhat-node-test-runner/test/index.ts Removes process.exitCode save/restore since runner no longer sets it.
v-next/hardhat-mocha/src/task-action.ts Returns Result<TestSummary, TestSummary> and uses successResult/errorResult.
v-next/hardhat-mocha/test/index.ts Updates expectations to match the new Result wrapper shape.
v-next/hardhat-mocha/test/env.ts Removes process.exitCode save/restore since runner no longer sets it.
.peer-bumps.json Updates peer bump reasons to include new Result helpers and TestSummary type usage.
.changeset/ninety-dolls-laugh.md Documents the new Result return pattern and TestSummary interface as a patch release.

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

Comment thread v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts
Comment thread v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Outdated
Comment thread v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Outdated
Comment thread v-next/hardhat/src/types/test.ts
Comment thread v-next/hardhat/src/internal/builtin-plugins/test/task-action.ts Outdated
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.

I think there are two small improvements that could be made, but in general looks good

Base automatically changed from task-result to main March 2, 2026 21:50
@schaable schaable force-pushed the task-result-actions branch from dc9cabb to d24c904 Compare March 2, 2026 21:56
return isObject(value);
// Old plugins may only return { failed, passed } without skipped/todo,
// so we accept a partial shape and fill defaults in the coordinator.
interface PartialTestSummary extends Omit<TestSummary, "skipped" | "todo"> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Older versions of hardhat-mocha didn't include skipped and todo in TestSummary. To keep these versions compatible, we make the fields optional and default them on lines 125-129:

      testSummaries[summaryId] = {
        skipped: 0,
        todo: 0,
        ...summary,
      };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good catch

@schaable schaable requested a review from alcuadrado March 3, 2026 03:27
@schaable schaable added this pull request to the merge queue Mar 5, 2026
Merged via the queue into main with commit 96a82c8 Mar 5, 2026
213 checks passed
@schaable schaable deleted the task-result-actions branch March 5, 2026 13:50
@github-actions github-actions Bot mentioned this pull request Mar 5, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants