Skip to content

test_runner: make signal handling configurable - #59674

Closed
mete0rfish wants to merge 7 commits into
nodejs:mainfrom
mete0rfish:feat-configure-signal-with-global-options
Closed

test_runner: make signal handling configurable#59674
mete0rfish wants to merge 7 commits into
nodejs:mainfrom
mete0rfish:feat-configure-signal-with-global-options

Conversation

@mete0rfish

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-botnodejs-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
@codecov

codecovBot commented Aug 29, 2025

Copy link
Copy Markdown

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 1511 commits behind head on main.

Files with missing linesPatch %Lines
lib/internal/test_runner/harness.js0.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 linesCoverage Δ
lib/internal/test_runner/runner.js92.82% <100.00%> (+0.01%)⬆️
lib/internal/test_runner/harness.js90.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 MoLowAugust 29, 2025 17:00
@pmarchini

Copy link
Copy Markdown
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? 😁

Comment threadlib/internal/test_runner/runner.js Outdated
@@ -593,6 +593,7 @@ function run(options = kEmptyObject) {
argv = [],
cwd = process.cwd(),
rerunFailuresFilePath,
hookSignal = false,

Copy link
Copy Markdown
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

Comment threadlib/internal/test_runner/harness.js Outdated
@@ -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
Copy Markdown
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){

Comment threadlib/internal/test_runner/runner.js Outdated
@@ -593,6 +593,7 @@ function run(options = kEmptyObject) {
argv = [],
cwd = process.cwd(),
rerunFailuresFilePath,
hookSignal = false,

Copy link
Copy Markdown
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
mete0rfishforce-pushed the feat-configure-signal-with-global-options branch from 1e772a1 to 54a6e25CompareSeptember 1, 2025 03:39
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ciPRs that need a full CI run.test_runnerIssues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@mete0rfish@nodejs-github-bot@pmarchini@MoLow