最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the best way to get coverage stats in cucumber js? - Stack Overflow

programmeradmin2浏览0评论

I'm designing my tests using the Behavior Driven Development (BDD) approach using Gherkin syntax and running my tests with Cucumber JS.

I'm using Cucumber Studio to share reports and keep synced with my business stakeholders, and management.

Recently I needed to get test coverage reports for the project, and made some research but couldn't decide which library to use to get coverage reports and how.

So far I've found JSCover, Cucumber Reports, and Istanbul for test coverage reports, but I'm not sure how to use them exactly and which would be best for my case to use with Cucumber JS.

I'm designing my tests using the Behavior Driven Development (BDD) approach using Gherkin syntax and running my tests with Cucumber JS.

I'm using Cucumber Studio to share reports and keep synced with my business stakeholders, and management.

Recently I needed to get test coverage reports for the project, and made some research but couldn't decide which library to use to get coverage reports and how.

So far I've found JSCover, Cucumber Reports, and Istanbul for test coverage reports, but I'm not sure how to use them exactly and which would be best for my case to use with Cucumber JS.

Share Improve this question asked Apr 11, 2021 at 9:46 ChoottiChootti 4866 silver badges16 bronze badges 2
  • Are you tests run in a browser? (like karma or selenium) or is everything run inside node.js? – Alex028502 Commented May 5, 2021 at 19:43
  • Actually currently they run on node executions, not on the browser directly. They include unit, ponent, integration, and e2e tests which don't require a browser to run. The most external test is E2E and it uses gRPC requests. – Chootti Commented May 11, 2021 at 17:49
Add a ment  | 

1 Answer 1

Reset to default 7

After several trials, I've figured out that it is pretty simple to use Istanbul JS to see code coverage.

I've followed the instructions on the website and install Istanbul's JavaScript library nyc using:

yarn add -D nyc

Then, I've updated my scripts in the package.json as the following:

...
  "scripts": {
    "test": "cucumber-js ...",
    ...
    "coverage": "nyc yarn test"
  },
...

And when I run yarn coverage it runs the tests with wrapping by nyc and creating a coverage report as the following:

发布评论

评论列表(0)

  1. 暂无评论