Skip to content

Node not saving coverage when process is terminated using SIGINT/SIGTERM #35212

Open
@aalexgabi

Description

@aalexgabi
  • Version: v14.10.1

What steps will reproduce the bug?

When running this code

function run() {
  if (1) {
    console.log(1);
  } else {
    console.log(2);
  }
}

run();

setTimeout(process.exit, 3000)

If I stop the process using SIGINT/SIGTERM before the timeout kicks in, coverage is not saved.

% NODE_V8_COVERAGE=/tmp/cov node /tmp/t.js
1
^C
% ls /tmp/cov
ls: cannot access '/tmp/cov': No such file or directory
% 

What is the expected behavior?

Node coverage should work in the same way as other coverage tools, saving the coverage before terminating the process even if no SIGINT handler is set.

What do you see instead?

No coverage is saved.

Additional information

I know that adding a SIGINT/SIGTERM handler can be used as a workaround but this is not how most applications terminate and has no added value.

process.on('SIGINT', () => process.exit())
process.on('SIGTERM', () => process.exit())

Metadata

Metadata

Assignees

No one assigned

    Labels

    coverageIssues and PRs related to native coverage support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions