Skip to content

Fix Node.js 22 test failures: correct assert import and use .mjs extension#14

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/fix-workflow-error-node-22
Closed

Fix Node.js 22 test failures: correct assert import and use .mjs extension#14
Copilot wants to merge 4 commits intomainfrom
copilot/fix-workflow-error-node-22

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 14, 2025

Node.js 22 tests failed with assert.strictEqual is not a function and module type warnings. The test file incorrectly imported assert from node:test instead of node:assert.

Changes

  • test/server.test.js → test/server.test.mjs: Renamed to use explicit ES module extension to eliminate module type warnings

    // Before
    import { test, assert } from 'node:test';
    
    // After
    import { test } from 'node:test';
    import assert from 'node:assert';
  • package.json: Updated test scripts from test/**/*.test.mjs to test/ for better cross-platform compatibility with Node.js test runner

  • test-direct.js, test-sdk.js: Renamed to .cjs extension to preserve CommonJS compatibility

Why .mjs instead of "type": "module"

The .mjs extension approach was chosen because the TypeScript build outputs CommonJS code (using exports). Adding "type": "module" to package.json would cause the compiled JavaScript to fail with ReferenceError: exports is not defined in ES module scope. Using .mjs allows the test file to use ES module syntax without affecting the build output format.

Why test/ instead of glob pattern

The 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

This section details on the original issue you should resolve

<issue_title>Fix workflow error on ubuntu node 22</issue_title>
<issue_description>Node 22 on ubuntu

> ozwellai-reference@1.0.0 test
> node --test test/**/*.test.js
TAP version 13
# (node:2212) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js is not specified and it doesn't parse as CommonJS.
# Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
# To eliminate this warning, add "type": "module" to /home/runner/work/ozwellai-api/ozwellai-api/reference-server/package.json.
# (Use `node --trace-warnings ...` to show where the warning was created)
# Subtest: Reference Server - Health Check
not ok 1 - Reference Server - Health Check
  ---
  duration_ms: 4048.404682
  type: 'test'
  location: '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:5:1'
  failureType: 'testCodeFailure'
  error: 'assert.strictEqual is not a function'
  code: 'ERR_TEST_FAILURE'
  name: 'TypeError'
  stack: |-
    TestContext.<anonymous> (file:///home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:18:12)
    process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    async Test.run (node:internal/test_runner/test:1054:7)
    async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3)
  ...
# Subtest: Reference Server - OpenAPI Spec
not ok 2 - Reference Server - OpenAPI Spec
  ---
  duration_ms: 4014.349457
  type: 'test'
  location: '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:34:1'
  failureType: 'testCodeFailure'
  error: 'assert.strictEqual is not a function'
  code: 'ERR_TEST_FAILURE'
  name: 'TypeError'
  stack: |-
    TestContext.<anonymous> (file:///home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:47:12)
    process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    async Test.run (node:internal/test_runner/test:1054:7)
    async Test.processPendingSubtests (node:internal/test_runner/test:744:7)

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: horner <6094599+horner@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix workflow error on Ubuntu Node 22 Fix Node.js 22 test failures: correct assert import and add ES module type Nov 14, 2025
Copilot AI requested a review from horner November 14, 2025 02:41
@horner
Copy link
Copy Markdown
Member

horner commented Nov 14, 2025

@copilot

node dist/reference-server/src/server.js

file:///home/runner/work/ozwellai-api/ozwellai-api/reference-server/dist/reference-server/src/server.js:38
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/runner/work/ozwellai-api/ozwellai-api/reference-server/dist/reference-server/src/server.js:38:23
    at ModuleJob.run (node:internal/modules/esm/module_job:325:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:606:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Co-authored-by: horner <6094599+horner@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 14, 2025

@copilot

node dist/reference-server/src/server.js

...

Fixed in commit 98cf624. The issue was that adding "type": "module" broke the build because TypeScript compiles to CommonJS.

The solution uses .mjs extension for the test file instead, which allows ES module syntax without changing the package module type. The server now builds and starts correctly.

Copilot AI changed the title Fix Node.js 22 test failures: correct assert import and add ES module type Fix Node.js 22 test failures: correct assert import and use .mjs extension Nov 14, 2025
@horner
Copy link
Copy Markdown
Member

horner commented Nov 14, 2025

location: '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:5:1'

error: 'assert.strictEqual is not a function'

@copilot

Co-authored-by: horner <6094599+horner@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 14, 2025

location: '/home/runner/work/ozwellai-api/ozwellai-api/reference-server/test/server.test.js:5:1'

error: 'assert.strictEqual is not a function'...

The assert.strictEqual is not a function error has been fixed. The test file now correctly imports assert from node:assert (not node:test) and uses the .mjs extension. The test script has also been updated to use test/ instead of a glob pattern. See commits d7365a4, 98cf624, and cef25de.

aditya-damerla128 added a commit to aditya-damerla128/ozwellai-api that referenced this pull request Dec 6, 2025
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.
horner pushed a commit that referenced this pull request Dec 9, 2025
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.
@aditya-damerla128
Copy link
Copy Markdown
Collaborator

Closing — target test files no longer exist on main. Node.js 22 compatibility has been addressed in the current test setup.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix workflow error on ubuntu node 22

3 participants