2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Node.js] istanbul でカバレッジが出力されないとき

Last updated at Posted at 2014-12-02

process.on("exit") で書き込み処理が実行されるので、テストにおいて process.removeListeners() でハンドラを削除してしまっていると出力されない。

ハンドラを削除する必要がある場合は、process.listeners("exit") で事前にハンドラを退避し、事後に設定し直すことで対応できる。下記は istanbul + mocha での場合。

var exitHandlers;

before(function () {
   exitHandlers = process.listeners("exit");
});

after(function () {
    exitHandlers.forEach(function (handler) {
        process.on("exit", handler);
    });
});
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?