Skip to content

feat: extend harness with assert methods, gcUntil, and --expose-gc#27

Merged
legendecas merged 1 commit intonodejs:mainfrom
kraenhansen:feat/harness-gc-asserts
Mar 3, 2026
Merged

feat: extend harness with assert methods, gcUntil, and --expose-gc#27
legendecas merged 1 commit intonodejs:mainfrom
kraenhansen:feat/harness-gc-asserts

Conversation

@kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Feb 28, 2026

Summary

  • Extends the assert global with .ok, .strictEqual, .notStrictEqual, .deepStrictEqual, and .throws methods
  • Adds gcUntil(name, condition) global for finalizer testing, with --expose-gc flag
  • Adds harness tests validating these globals before tests rely on them
  • Updates CMakeLists.txt to support multi-source addons via ARGN

Test plan

  • npm run node:test — all 8 tests pass (3 harness + 1 existing test)

🤖 Generated with Claude Code

function(add_node_api_cts_addon ADDON_NAME SRC)
add_library(${ADDON_NAME} SHARED ${SRC})
function(add_node_api_cts_addon ADDON_NAME)
add_library(${ADDON_NAME} SHARED ${ARGN})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const assert = (value, message) => {
ok(value, message);
};
const assert = Object.assign(
Copy link
Member

@legendecas legendecas Mar 2, 2026

Choose a reason for hiding this comment

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

Non-blocking: I would prefer avoiding the assert() and assert.<method> style in this harness. We could update test cases to use proper asserts like assert.strictEqual whenever possible.

Copy link
Contributor Author

@kraenhansen kraenhansen Mar 3, 2026

Choose a reason for hiding this comment

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

That was my initial thought as well (which is why I didn't add it initially).

I realised later as I was porting tests that it's probably more important that the tests are ported as close to their original source as possible - to minimise the risk of loosing coverage. With these helpers it's more obvious that we're actually testing the same as the Node.js test suite.

I suggest we keep this as is for now and when we have more tests ported and ideally multiple implementors running these tests we can start refactoring them in isolation.

How does that plan sound to you?

Adds the following to the Node.js implementor and harness in preparation
for porting the easy js-native-api tests:

- assert.js: expose assert.ok, .strictEqual, .notStrictEqual,
  .deepStrictEqual, and .throws as methods on the global assert object
- gc.js: new module providing a global gcUntil(name, condition) helper
  that drives GC until a condition is met (needed for finalizer tests)
- tests.ts: inject --expose-gc and gc.js into every test subprocess
- CMakeLists.txt: broaden add_node_api_cts_addon() to accept multiple
  source files via ARGN (needed for multi-file addons)
- tests/harness/assert.js: exercise all new assert methods
- tests/harness/gc.js: exercise gcUntil pass and failure paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kraenhansen kraenhansen force-pushed the feat/harness-gc-asserts branch from c0c854d to 2b4c2df Compare March 3, 2026 08:17
@legendecas legendecas merged commit 186ab0e into nodejs:main Mar 3, 2026
13 checks passed
@github-project-automation github-project-automation bot moved this from Need Triage to Done in Node-API Team Project Mar 3, 2026
@kraenhansen kraenhansen deleted the feat/harness-gc-asserts branch March 7, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants