Skip to content

Conversation

mete0rfish
Copy link
Contributor

This PR resolves a TODO in the test runner to allow signal handling to be enabled.

Purpose

The test runner's signal handlers are only attached when it is invoked via the --test CLI flag (isTestRunner === true). This
prevents users from opting into the same behavior in scenarios where isTestRunner === false, such as when calling the run() API from a JS file. In these cases, a SIGINT signal would terminate the process abruptly without proper test reporting.

Therefore this PR introduces a new hookSignal option to the run() function, allowing developers to enable signal handling for these scenarios.

I would appreciate your feedback😄

Related Issues

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Aug 29, 2025
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.93%. Comparing base (bfcba89) to head (54a6e25).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/harness.js 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59674      +/-   ##
==========================================
+ Coverage   89.91%   89.93%   +0.02%     
==========================================
  Files         667      667              
  Lines      196600   196793     +193     
  Branches    38594    38421     -173     
==========================================
+ Hits       176766   176981     +215     
+ Misses      12270    12211      -59     
- Partials     7564     7601      +37     
Files with missing lines Coverage Δ
lib/internal/test_runner/runner.js 92.82% <100.00%> (+0.01%) ⬆️
lib/internal/test_runner/harness.js 90.84% <0.00%> (-0.99%) ⬇️

... and 75 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pmarchini pmarchini requested a review from MoLow August 29, 2025 17:00
@pmarchini
Copy link
Member

Hey @mete0rfish, thanks for the contribution! I'll take a look ASAP.
I've also requested a review from @MoLow, since he's the one who left the TODO.

In the meantime, I noticed that the commit validation is failing...could you please take a look at it? 😁

@@ -593,6 +593,7 @@ function run(options = kEmptyObject) {
argv = [],
cwd = process.cwd(),
rerunFailuresFilePath,
hookSignal = false,
Copy link
Member

Choose a reason for hiding this comment

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

If we decide to add a new property to the run method, we also need to update the documentation:
https://github.com/nodejs/node/blob/fb614c43240158fa6c5b988571746fadff8e22d7/doc/api/test.md?#runoptions

@@ -297,8 +297,7 @@ function setupProcessState(root, globalOptions) {
process.on('uncaughtException', exceptionHandler);
process.on('unhandledRejection', rejectionHandler);
process.on('beforeExit', exitHandler);
// TODO(MoLow): Make it configurable to hook when isTestRunner === false.
if (globalOptions.isTestRunner) {
if (globalOptions.isTestRunner || globalOptions.hookSignal === true) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (globalOptions.isTestRunner || globalOptions.hookSignal === true) {
if (globalOptions.isTestRunner && globalOptions.hookSignal !== false) {

@@ -593,6 +593,7 @@ function run(options = kEmptyObject) {
argv = [],
cwd = process.cwd(),
rerunFailuresFilePath,
hookSignal = false,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
hookSignal = false,
hookSignal = true,

please preserve the current behavior as the default behavior

@mete0rfish mete0rfish force-pushed the feat-configure-signal-with-global-options branch from 1e772a1 to 54a6e25 Compare September 1, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants