Skip to content

feat: port test_cannot_run_js to CTS#28

Draft
kraenhansen wants to merge 6 commits intonodejs:mainfrom
kraenhansen:feat/port-test-cannot-run-js
Draft

feat: port test_cannot_run_js to CTS#28
kraenhansen wants to merge 6 commits intonodejs:mainfrom
kraenhansen:feat/port-test-cannot-run-js

Conversation

@kraenhansen
Copy link
Contributor

Note

This PR is stacked on #25 and should not be reviewed or merged until that PR lands.

Summary

  • Ports test_cannot_run_js from node/test/js-native-api/ to the CTS
  • Builds two addons from the same C source (test_cannot_run_js with NAPI_VERSION=10, test_pending_exception with NAPI_VERSION=9) to cover both code paths in the finalizer
  • Verifies that when a finalizer tries to access JS during environment shutdown, napi_get_named_property returns napi_cannot_run_js (v10+), napi_pending_exception (v9), or napi_ok if the event loop is still running

Test plan

  • npm run addons:configure && npm run addons:build — both addons compile cleanly
  • npm run node:test — all 48 tests pass, including test_cannot_run_js

🤖 Generated with Claude Code

kraenhansen and others added 6 commits February 28, 2026 12:35
Enumerates all 58 test directories from Node.js's test/js-native-api
and test/node-api, rates each by porting difficulty (Easy/Medium/Hard),
and documents special considerations for tests with deep runtime
dependencies (libuv, worker threads, SEA, node_api_post_finalizer, etc.).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
Port all "Easy" difficulty engine-specific tests from Node.js:
3_callbacks, 4_object_factory, 5_function_factory, 7_factory_wrap,
8_passing_wrapped, test_array, test_bigint, test_dataview, test_date,
test_handle_scope, test_instance_data, test_new_target, test_number,
test_promise, test_properties, test_reference_double_free, test_symbol.

C/C++ sources are copied from Node.js with minimal changes (entry_point.h
macro). JS tests are adapted to use CTS globals (loadAddon, assert,
gcUntil) instead of Node.js test harness (common.js, require).

test_dataview: removed SharedArrayBuffer tests that depend on experimental
node_api_is_sharedarraybuffer API (not in stable node-api-headers).

Also updates node-api-headers from 1.7.0 to 1.8.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Mark 17 easy js-native-api tests as Ported (test_dataview as Partial due
to missing experimental SharedArrayBuffer APIs in node-api-headers).

Add "Experimental Node-API Features" section documenting which tests
depend on experimental APIs not yet available in node-api-headers, and
the approach needed to support them. References nodejs#26.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Builds two addons from the same C source with different NAPI_VERSION
defines (10 and 9) to verify that finalizers attempting to access JS
during shutdown receive napi_cannot_run_js or napi_pending_exception
(respectively), or napi_ok if the event loop is still running.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kraenhansen
Copy link
Contributor Author

kraenhansen commented Mar 8, 2026

This fails on Node v20, we might want to just remove that from the test matrix as active support ended 22 Oct 2024?

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

Labels

None yet

Projects

Status: Need Triage

Development

Successfully merging this pull request may close these issues.

1 participant