Fix Node.js 22 test failures: correct assert import and use .mjs extension#14
Fix Node.js 22 test failures: correct assert import and use .mjs extension#14
Conversation
Co-authored-by: horner <6094599+horner@users.noreply.github.com>
|
Co-authored-by: horner <6094599+horner@users.noreply.github.com>
... Fixed in commit 98cf624. The issue was that adding The solution uses |
|
location: '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:5:1' error: 'assert.strictEqual is not a function' |
Co-authored-by: horner <6094599+horner@users.noreply.github.com>
The |
The default import of node:assert doesn't expose strictEqual as a function on Node 22, causing tests to fail with 'assert.strictEqual is not a function'. This was causing CI workflows to hang indefinitely because: 1. Tests failed immediately but spawned orphan server processes 2. Orphan processes didn't exit, blocking workflow completion 3. Workflow had to be manually cancelled after 2 hours Changed to import from node:assert/strict which properly exports the strict assertion functions. Same fix as mieweb#14 Fixes workflow hang on Node.js 22 (ubuntu-latest) runner.
The default import of node:assert doesn't expose strictEqual as a function on Node 22, causing tests to fail with 'assert.strictEqual is not a function'. This was causing CI workflows to hang indefinitely because: 1. Tests failed immediately but spawned orphan server processes 2. Orphan processes didn't exit, blocking workflow completion 3. Workflow had to be manually cancelled after 2 hours Changed to import from node:assert/strict which properly exports the strict assertion functions. Same fix as #14 Fixes workflow hang on Node.js 22 (ubuntu-latest) runner.
|
Closing — target test files no longer exist on main. Node.js 22 compatibility has been addressed in the current test setup. |
Node.js 22 tests failed with
assert.strictEqual is not a functionand module type warnings. The test file incorrectly importedassertfromnode:testinstead ofnode:assert.Changes
test/server.test.js → test/server.test.mjs: Renamed to use explicit ES module extension to eliminate module type warnings
package.json: Updated test scripts from
test/**/*.test.mjstotest/for better cross-platform compatibility with Node.js test runnertest-direct.js, test-sdk.js: Renamed to
.cjsextension to preserve CommonJS compatibilityWhy .mjs instead of "type": "module"
The
.mjsextension approach was chosen because the TypeScript build outputs CommonJS code (usingexports). Adding"type": "module"to package.json would cause the compiled JavaScript to fail withReferenceError: exports is not defined in ES module scope. Using.mjsallows the test file to use ES module syntax without affecting the build output format.Why
test/instead of glob patternThe Node.js test runner doesn't consistently expand glob patterns across all platforms. Using the directory path (
test/) instead of a glob pattern (test/**/*.test.mjs) allows Node to automatically discover test files reliably.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.