Skip to content

Port hardhat ignition tests from mocha to node - #8870

Open
kanej wants to merge 9 commits into
mainfrom
port-hardhat-ignition-tests-from-mocha-to-node
Open

kanej wants to merge 9 commits into
mainfrom
port-hardhat-ignition-tests-from-mocha-to-node

Conversation

@kanej

@kanej kanej commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Port the Ignition plugin package from mocha to node:test.

Review

Tip

Review a commit at a time

  • The first commit reworks helper fixture functions (we are keeping these for the moment over the version in utils) to not use this. A pattern mocha allows but node:test does not.
  • The second fixes up a bug that showed up once node:test was in play.
  • The third commit switches to node:test but keeps chai assert
  • A series of commits port from chai assert to node's own assert, each commit shifts a different pattern of usage
  • final commit is cleanup

@kanej
kanej added this pull request to stack #8871 November 20, 2026 17:40
@kanej kanej added no changeset needed This PR doesn't require a changeset no docs needed This PR doesn't require links to documentation no peer bump needed labels Nov 20, 2026
chainUpdates: (c: TestChainHelper) => Promise<void>,
) => ReturnType<typeof runDeploy>;
config: Partial<DeployConfig>;
}

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.

Pass it explicitly rather than attaching it to the mocha context.

@kanej
kanej force-pushed the port-hardhat-ignition-tests-from-mocha-to-node branch from 59783bf to 8a6a555 Compare November 20, 2026 17:56
@NomicFoundation NomicFoundation deleted a comment from changeset-bot Bot Nov 20, 2026
@NomicFoundation NomicFoundation deleted a comment from github-actions Bot Nov 20, 2026
};
// Handle both outcomes: `finished.finally()` would return a second promise
// that rejects whenever `finished` does, and nothing would handle it.
void finished.then(stop, stop);

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.

This is a bug claude found in the helper.
Basically stop, stop means pass stop whether we resolve or reject.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test migration introduces shared-fixture races, skips required Ignition setup, removes coverage enforcement, and leaves tests without finite timeouts.

4 open issues
1 file not reviewed
  • pnpm-lock.yaml: Generated file
What changed in this PR

Migrates the Hardhat Ignition plugin’s tests from Mocha and Chai to Node’s built-in test runner, aligning the package with the repository’s test tooling.

Changes:

  • Converts suites, hooks, assertions, and fixture access to node:test and explicit project objects.
  • Replaces nyc with c8, updates dependencies, and enables Ignition in test:file.
  • Adds local Sinon cleanup and prevents unhandled rejections in the pending-transaction helper.
File Description
scripts/​test-file.ts Enables Ignition test-file runs.
pnpm-lock.yaml Updates test-tool dependencies.
packages/​hardhat-ignition/​tsconfig.json Removes Mocha global types.
packages/​hardhat-ignition/​test/​utils/​resolve-deployment-id.ts Migrates deployment-ID assertions.
packages/​hardhat-ignition/​test/​utils/​open.ts Migrates command-selection tests.
packages/​hardhat-ignition/​test/​utils/​load-module.ts Uses structured Hardhat error assertions.
packages/​hardhat-ignition/​test/​utils/​error-deployment-result-to-exception-message.ts Migrates error-formatting tests.
packages/​hardhat-ignition/​test/​utils/​bigintReviver.ts Migrates bigint utility tests.
packages/​hardhat-ignition/​test/​ui/​pretty-event-handler.ts Migrates UI tests and restores Sinon stubs.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-starting-message.ts Migrates starting-message tests.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-list-transactions-display.ts Migrates transaction-display tests.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-deployment-status-display.ts Migrates status-display tests.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-deployment-complete-display.ts Migrates completion-display tests.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-deploying-module-panel-display.ts Migrates module-panel tests.
packages/​hardhat-ignition/​test/​ui/​helpers/​calculate-batch-display.ts Migrates batch-display tests.
packages/​hardhat-ignition/​test/​test-helpers/​wait-for-pending-txs.ts Handles both deployment promise outcomes.
packages/​hardhat-ignition/​test/​test-helpers/​use-ignition-project.ts Replaces Mocha context with project objects.
packages/​hardhat-ignition/​test/​test-helpers/​clear-pending-transactions-from-memory-pool.ts Uses Node assertions.
packages/​hardhat-ignition/​test/​tasks/​verify.ts Migrates verification-task tests.
packages/​hardhat-ignition/​test/​strategies/​only-built-in-strategies.ts Migrates strategy validation tests.
packages/​hardhat-ignition/​test/​strategies/​generic-strategy-constraints.ts Migrates strategy tests and bigint expectations.
packages/​hardhat-ignition/​test/​strategies/​create2.ts Migrates CREATE2 assertions and fixtures.
packages/​hardhat-ignition/​test/​setup.ts Removes global Mocha/Chai setup.
packages/​hardhat-ignition/​test/​plan/​index.ts Uses explicit visualization-test fixtures.
packages/​hardhat-ignition/​test/​plan/​build-invocation.ts Migrates visualization build tests.
packages/​hardhat-ignition/​test/​module-parameters.ts Migrates parameter and error assertions.
packages/​hardhat-ignition/​test/​module-api/​use-module.ts Migrates module-composition tests.
packages/​hardhat-ignition/​test/​module-api/​static-calls.ts Migrates static-call tests.
packages/​hardhat-ignition/​test/​module-api/​params.ts Migrates parameter API tests.
packages/​hardhat-ignition/​test/​module-api/​libraries.ts Migrates library deployment tests.
packages/​hardhat-ignition/​test/​module-api/​fully-qualified-names.ts Migrates qualified-name tests.
packages/​hardhat-ignition/​test/​module-api/​existing-contract.ts Migrates existing-contract tests.
packages/​hardhat-ignition/​test/​module-api/​events.ts Migrates event-reading tests.
packages/​hardhat-ignition/​test/​module-api/​contracts.ts Migrates contract deployment tests.
packages/​hardhat-ignition/​test/​module-api/​calls.ts Migrates contract-call tests.
packages/​hardhat-ignition/​test/​migrate/​verifyArtifactsVersion.ts Migrates artifact-version checks.
packages/​hardhat-ignition/​test/​migrate/​migrate.ts Migrates deployment migration tests.
packages/​hardhat-ignition/​test/​integration/​chain-id.ts Migrates chain-ID reconciliation tests.
packages/​hardhat-ignition/​test/​integration/​basic-success.ts Migrates CI deployment smoke test.
packages/​hardhat-ignition/​test/​deploy/​writeLocalhost.ts Migrates localhost persistence tests.
packages/​hardhat-ignition/​test/​deploy/​timeouts/​deploy-run-times-out.ts Migrates deployment-timeout assertions.
packages/​hardhat-ignition/​test/​deploy/​reset.ts Migrates deployment-reset tests.
packages/​hardhat-ignition/​test/​deploy/​rerun/​rerun-with-new-contract-deploy.ts Migrates incremental rerun tests.
packages/​hardhat-ignition/​test/​deploy/​rerun/​rerun-after-kill.ts Migrates interrupted-deployment tests.
packages/​hardhat-ignition/​test/​deploy/​rerun/​rerun-a-deploy-that-timed-out.ts Migrates timeout recovery tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​revert-nonce-on-simulation-error.ts Migrates simulation-error assertions.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​rerun-with-replaced-confirmed-user-transaction.ts Migrates confirmed-replacement tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​rerun-with-pending-ignition-transactions.ts Migrates pending-transaction rerun tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​rerun-with-now-complete-ignition-transactions.ts Migrates completed-transaction rerun tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​rerun-with-dropped-ignition-transaction.ts Migrates dropped-transaction recovery tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​error-on-user-transaction-sent.ts Migrates user-interference tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​error-on-transaction-dropped.ts Migrates dropped-transaction error tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​error-on-rerun-with-replaced-pending-user-transaction.ts Migrates pending-replacement error tests.
packages/​hardhat-ignition/​test/​deploy/​nonce-checks/​error-on-pending-user-transactions.ts Migrates pending-user-transaction tests.
packages/​hardhat-ignition/​test/​deploy/​multiple-batch-contract-deploy.ts Migrates multi-batch deployment tests.
packages/​hardhat-ignition/​test/​deploy/​gas-estimation.ts Migrates gas-estimation error assertions.
packages/​hardhat-ignition/​test/​deploy/​default-sender.ts Migrates default-sender tests.
packages/​hardhat-ignition/​test/​deploy/​build-profile.ts Migrates build-profile tests.
packages/​hardhat-ignition/​test/​deploy/​build-invocation.ts Migrates deployment build tests.
packages/​hardhat-ignition/​test/​config.ts Migrates configuration tests.
packages/​hardhat-ignition/​package.json Configures Node tests, c8, and dependencies.
packages/​hardhat-ignition/​.nycrc Removes nyc configuration.
packages/​hardhat-ignition/​.mocharc.json Removes Mocha configuration.

Review effort: Balanced

Comment thread packages/hardhat-ignition/package.json Resolved
Comment thread packages/hardhat-ignition/package.json Resolved
Comment thread scripts/test-file.ts Resolved
Comment thread scripts/test-file.ts Resolved
Base automatically changed from port-ignition-core-tests-from-mocha-to-node to main November 20, 2026 18:29
useEphemeralIgnitionProject and useFileIgnitionProject set hre,
connection, ignition and the rest on Mocha's this. Have them return an
object they fill in before each test instead, and read project.hre
where tests read this.hre. Mocha still runs the tests; this removes the
one thing node:test has no equivalent for.
waitForPendingTxs stops polling when the deploy settles, through
finished.finally(). That returns a second promise, which rejects
whenever the deploy does, as it does on purpose when a test kills a
deploy, and nothing handles it. Mocha lets the unhandled rejection
pass; node:test fails the test that is running. Use then() with the
same callback for both outcomes instead.
Move test from Mocha to node --test with the repo's test reporter,
importing describe, it and the hooks from node:test. Chai stays for
now: test/setup.ts is loaded with --import so chai-as-promised is still
registered.

--test-concurrency=1 keeps Mocha's one-file-at-a-time order. The tests
build and deploy inside the shared fixture projects, so files running in
parallel collide there.

node:test hooks take options, not a title, so the hook titles go. The
three this.timeout(60000) calls go too, as node:test has no default
timeout to raise. setup.ts's root sinon.restore() moves into the one
file that relied on it.
assert.isDefined(x) becomes assert.notEqual(x, undefined), and
assert.isNotNull(x) becomes assert.ok(x !== null), which narrows the
type as isNotNull did.
isTrue and isFalse become assert.equal(x, true|false), and include
becomes assert.ok over .includes().
isFulfilled(p) becomes a plain await of p. isRejected and throws become
hardhat-test-utils' assertRejects and assertThrows, checking the error
message against the same regex or substring. Files left with no chai
assertion drop the chai import.
Seven of the rewritten error assertions are HardhatErrors: compare them
with assertRejectsWithHardhatError and assertThrowsHardhatError, by
descriptor and message arguments, instead of by message text. The
module-outside-directory test keeps its Windows path separator as a
message argument.
Swap chai's assert for node:assert/strict. The assertions left after
the previous commits are the same calls in both.

node:assert/strict compares with ===, where chai's equal is loose. Some
tests relied on that: contract reads return bigints but were compared
with numbers, and one balance is a hex string compared with a bigint.
Their expected values are now bigints, and the balance is converted.
@kanej
kanej force-pushed the port-hardhat-ignition-tests-from-mocha-to-node branch from 8a6a555 to 5e71e3d Compare November 20, 2026 18:29
The tests now run on node:test with node:assert, so delete
.mocharc.json, .nycrc and test/setup.ts, drop the Mocha, chai,
chai-as-promised and nyc dependencies, and measure coverage with c8,
one file at a time as the tests run.
@kanej
kanej force-pushed the port-hardhat-ignition-tests-from-mocha-to-node branch from 5e71e3d to 3cdd19e Compare November 20, 2026 21:52
@NomicFoundation NomicFoundation deleted a comment from github-actions Bot Nov 20, 2026
@NomicFoundation NomicFoundation deleted a comment from changeset-bot Bot Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

hardhat

Total size of the bundle: 42M
Total number of dependencies (including transitive): 38

List of dependencies (sorted by size)
33M	total
7.3M	@sentry/core
5.2M	zod
3.8M	micro-eth-signer
2.2M	undici
2.2M	@noble/curves
1.8M	@noble/hashes
1.5M	@nomicfoundation/hardhat-utils
1.1M	@noble/ciphers
884K	@nomicfoundation/hardhat-vendored
792K	@streamparser/json
700K	@nomicfoundation/hardhat-errors
536K	@scure/bip39
508K	ethereum-cryptography
504K	tsx
468K	micro-packed
408K	json-stream-stringify
320K	enquirer
320K	@nomicfoundation/hardhat-zod-utils
312K	semver
216K	adm-zip
208K	@scure/base
204K	ws
188K	@streamparser/json-node
168K	esbuild
160K	fast-equals
156K	@nomicfoundation/edr
108K	@scure/bip32
100K	chokidar
80K	p-map
72K	@nomicfoundation/solidity-analyzer
56K	rfdc
48K	ansi-colors
44K	resolve.exports
44K	readdirp
24K	strip-ansi
24K	is-safe-filename
24K	env-paths
24K	ansi-regex

@kanej
kanej marked this pull request as ready for review November 20, 2026 21:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changeset needed This PR doesn't require a changeset 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.

2 participants