4

nyc を使用してカバレッジ レポートを取得しようとしていますが、cross-env プラグインを使用していない場合はうまく機能します。

cross-env NODE_ENV=test nyc mocha --ui bdd --reporter spec --colors --require babel-core/register tests --recursive

このコマンドを実行すると、コード カバレッジが正しく実行されず、結果は次のようになります。

 31 passing (1s)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

ただし、これを実行するnyc mocha --ui bdd --reporter spec --colors --require babel-core/register tests --recursiveと、期待どおりに動作します。

---------------------|----------|----------|----------|----------|-------------------|
File                 |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
---------------------|----------|----------|----------|----------|-------------------|
All files            |    79.45 |    64.29 |    35.71 |    84.62 |                   |
 constants           |      100 |      100 |      100 |      100 |                   |
  index.js           |      100 |      100 |      100 |      100 |                   |
 db                  |    77.05 |    64.29 |    33.33 |    83.02 |                   |
---------------------|----------|----------|----------|----------|-------------------|

問題は、テストを適切に実行できる rewire プラグインを使用するために env 変数を設定する必要があることです (実際、ほとんどのテストはそのために失敗しています)。

これは私の .bebelrc です

{
  "presets": ["es2015"],
  "env": {
    "test": {
      "plugins": ["istanbul", "babel-plugin-rewire"]
    }
  }
}

:問題はbabel-plugin-rewireに関連していると思います。実際、cross-envを削除してプラグイン コレクションをルートに配置しても、同じ空のカバレッジ結果が得られます。

4

1 に答える 1