Repository navigation
chore: Replace mocha and sinon with node:test - #247
Merged
Merged
Conversation
RobinBol
force-pushed
the
chore/docs-preview-without-serve
branch
from
October 22, 2026 15:05
598d9b9 to
8b055a7
Compare
RobinBol
force-pushed
the
chore/node-test
branch
from
October 22, 2026 15:05
cac64c7 to
71d878e
Compare
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking issues in the callback conversions, mock replacements, timer sequencing, or dependency cleanup.
No open issues 🎉
What changed in this PR
Replaces Mocha and Sinon with Node.js’s built-in test runner and mocking APIs for the Zigbee cluster library, without changing production code.
Changes:
- Migrates test imports, hooks, spies, and stubs, including all 22 callback-style tests.
- Adds a five-second test timeout and replaces the response-timeout test’s real delay with mock timers.
- Removes obsolete dependencies and Mocha lint globals, and updates contributor documentation.
| File | Description |
|---|---|
| test/testZCLError.js | Imports built-in test functions. |
| test/testTrxSequenceNumber.js | Converts random-value stubbing and mock cleanup. |
| test/testNode.js | Migrates spies and call assertions to native mocks. |
| test/testMfgSpecificCommands.js | Updates 17 callback tests to accept test context first. |
| test/testConfigureReportingRecordsStruct.js | Imports built-in test functions. |
| test/testClusterResponseTimeout.js | Migrates mocks and replaces the real delay with mock timers. |
| test/ota.js | Imports built-in test functions. |
| test/onOff.js | Imports built-in test functions. |
| test/levelControl.js | Imports built-in test functions. |
| test/iasZone.js | Converts notification callback tests. |
| test/endpointStandalone.js | Imports built-in test functions. |
| test/doorLock.js | Converts notification callback tests. |
| test/defaultResponse.js | Imports built-in test functions. |
| test/colorControl.js | Migrates frame spies and mock cleanup. |
| test/boundClusterAttributeStatus.js | Imports built-in test functions. |
| test/attributeReport.js | Converts the attribute-report callback test. |
| README.md | Updates the documented test framework. |
| package.json | Switches test runners and removes Mocha and Sinon dependencies. |
| package-lock.json | Removes obsolete test dependency entries. |
| eslint.config.js | Removes Mocha globals. |
| AGENTS.md | Documents native test commands and callback signatures. |
Review effort: Balanced
RobinBol
force-pushed
the
chore/docs-preview-without-serve
branch
from
October 23, 2026 07:32
bd3b924 to
98eabb9
Compare
RobinBol
force-pushed
the
chore/node-test
branch
from
October 23, 2026 07:32
5b32716 to
7a12860
Compare
node:test covers describe/it/hooks and the mock API covers the four sinon sandbox uses (spy, stub, callsFake, restore), so both packages and @types/sinon can go. Two things node:test does differently: - A callback test must take the context first, function(t, done). With function(done) node:test treats the test as synchronous, passes it and never runs the assertions. All 22 callback tests are updated. - There is no default test timeout, so a done that never fires hangs instead of failing. --test-timeout=5000 restores mocha's safety net. The one test that waited on a real 150ms timer now uses mock.timers.
The test files already require `node:test` on the line above, so the unprefixed `assert` next to it was the odd one out.
RobinBol
force-pushed
the
chore/docs-preview-without-serve
branch
from
October 23, 2026 08:05
98eabb9 to
96d21d5
Compare
RobinBol
force-pushed
the
chore/node-test
branch
from
October 23, 2026 08:05
7a12860 to
5bd4b42
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
mocha and sinon out,
node:testin.@types/sinongoes with them.Why
The suite barely used either. mocha:
describe,itand the four hooks, nothis.timeout, no.only, no chai; assertions were alreadynode:assert. sinon:createSandboxin four files, and from itspy,stub().callsFake(),stub().returns()andrestore(). All of it maps onto themockAPI one for one.How
22 callback tests were silently asserting nothing. With
function(done)node:test sees a one-parameter function, treats the test as synchronous, passes it and never runs the assertions:All 22 are now
function(t, done)(testMfgSpecificCommands.js17,doorLock.js2,iasZone.js2,attributeReport.js1). This is the main thing to review here.node:test has no default timeout, so a
donethat never fires hangs instead of failing after 2000ms. Hence--test-timeout=5000. Sabotaging an assertion inside adonehandler hung for 120s without it and fails properly with it, which doubles as proof the converted tests really do assert.The only real delay is gone.
testClusterResponseTimeout.jswaited 150ms against a 100ms command timeout; it now usesmock.timers. Still load-bearing: moving thesetTimeoutinlib/Cluster.jsout ofsendFrame().then()fails both the old version (102ms) and the new one (1.7ms).test/*.jskeeps exactly mocha's file set; a barenode --testwould also pick uptest/util/andtest/manual/, which are helpers.Testing
npm ci && npm test-> 114 pass, 0 fail. Five consecutive runs, no unhandled rejections, no flakes.lint,format:check,build,generate-typeswith an unchangedindex.d.tsandtsc --noEmitall clean.With the four PRs before it: devDependencies 14 -> 9, lockfile 584 -> 203 entries,
npm audit19 -> 2. The two left aretaffydbvia@athombv/jsdoc-template.