5

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.

Chootti
  • 357
  • 3
  • 15
  • Are you tests run in a browser? (like karma or selenium) or is everything run inside node.js? – Alex028502 May 05 '21 at 19:43
  • 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. – Chootti May 11 '21 at 17:49

1 Answers1

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

Chootti
  • 357
  • 3
  • 15