Chutzpah coverage result smaller than 100% (due to

2019-05-20 23:20发布

I use Chutzpah to test my JavaScript test coverage. Here is an example for the coverage result when I run a single test file referenceFigureEdit.spec.js:

enter image description here

I would expect the coverage to be 100% but it is only 91.07%.

Clicking on the first line I can inspect my tested code in detail. Lines that are "not covered by the test" are highlighted:

enter image description here

Question A:

How can I

  • tell Chutzpah that those methods have actually been executed or
  • tell Chutzpah to not include those lines in the coverage result?

Are there some restrictions on where/when code has to be executed to be part of the successful coverage? I call the delegates inside my it-methods. Do they already need to be called during the construction of the module under test?

My tested code defines some delegate methods (e.g. "showErrors") that are passed to constructors (e.g. new saveCommand(..., showErrors)). The method declarations of that delegates are highlighted and not included in the coverage. However, those delegates are actually executed during the test and I would expect the coverage to be 100 %.

Even if the code in the showErrors delegate is private I would like to test it (whether private methods should be tested is not my question here). In order to execute the delegates in my tests, I mock the saveCommand. The mocked saveCommand publishes the passed delegate and in the test I explicitly call it:

sut.saveCommand.__showErrors();
expect(showAllMessagesSpy).toHaveBeenCalled();

The test executes successfully and is fine for me. However, the coverage result is not as expected.

Question B:

The main coverage results for the referenced file errorhandler.js shows a coverage of 27.59 %. I do not yet have a test for errorhandler.js. Does that number mean that 8 of the existing 29 statements of the errorhandler.js are executed while executing my main file referenceFigureEdit.js? My main file directly references errorhandler.js but does not directly reference utils.js. Where can I find some documentation on how to interpret those "sub-numbers" correctly and what is the purpose of the Total of 47.66% ?

1条回答
疯言疯语
2楼-- · 2019-05-20 23:48

I can answer Question A: You can use the chutzpah.json file to specify exclusions: "CodeCoverageExcludes": ["path1","path2","path3","etc"] As far as I know, you can only exclude files, though, not specific lines.

Update: yeah, blanket.js is the default code coverage tool, and it only excludes at the file level.

Question B I'm also trying to figure out.

查看更多
登录 后发表回答