New: Add unit tests using Node.js built-in test runner #48
+557
−35
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.
New
node:testandnode:assert/strictnpm test).gitignoreto exclude node_modules and build artifactsTesting
npm testto execute 31 tests across 3 modulesnpx standardto verify code style complianceOriginal prompt
This section details on the original issue you should resolve
<issue_title>Add unit tests</issue_title>
<issue_description># Writing tests
Instructions for writing tests in this module.
Stack
node:test(built into Node.js)node:assert/strictNo external test dependencies are needed. Do not introduce Mocha, Jest, or other test frameworks.
File placement and naming
tests/directory at the module root<moduleName>.spec.jstests/data/File structure
Every test file follows this structure:
Key rules:
describe,it,before,afteretc. fromnode:testassertfromnode:assert/strict(strict mode usesdeepStrictEqualby default)importsyntax — this project is"type": "module"describeblocks, prefixed with#for instance methodsletvariables scoped to thedescribeblockAssertions
Use
node:assert/strict. Common patterns:Dynamic test generation
When testing a function against multiple inputs, generate tests in a loop:
Async tests
node:testsupportsasync/awaitdirectly:Test data
Place fixture files in
tests/data/. Useimportorfsto load them:What to test
assert.throws/assert.rejects)What NOT to do
_)node:testandnode:assertare sufficientdescribeblocksAdd script to package.json
The tests should be accessible via an npm script in package.json:
Add GitHub workflow
The following workflow should be added to /.github:
Running tests
Both must pass before submitting a pull request.
</issue_description>
Comments on the Issue (you are @copilot in this section)
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.