What is the best way to get coverage stats in cucumber js?
Asked Answered
B

1

6

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.

Bash answered 11/4, 2021 at 9:46 Comment(2)
Are you tests run in a browser? (like karma or selenium) or is everything run inside node.js?Bradbury
Actually currently they run on node executions, not on the browser directly. They include unit, component, integration, and e2e tests which don't require a browser to run. The most external test is E2E and it uses gRPC requests.Bash
B
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:

enter image description here

Bash answered 11/5, 2021 at 17:58 Comment(3)
I believe you see the coverage (lines executed) in your test files, which is probably different from the results you expect - coverage of your application.Neb
You are mentioning: all the files vs the src file difference, am I right?Bash
If you want to use it without installing try npx nyc yarn testElsa

© 2022 - 2024 — McMap. All rights reserved.