npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bamboo-mocha-jest-code-coverage

v1.0.0

Published

Formats Jest code coverage report for Bamboo's Mocha Test Parser, so Bamboo can consume Jest code coverage reports.

Downloads

940

Readme

Bamboo Mocha Jest Code Coverage

Convert Jest Code Coverage Reports for Atlassian's Bamboo and Mocha Test Parser

Bamboo Mocha Jest Code Coverage is a utility that converts the JSON Summary generated by Jest's code coverage into a JSON object that Bamboo's Mocha Test Parser task can understand.

This lets developers using Atlassian's Bamboo to make code coverage part of a build's stages and jobs. If code coverage thresholds are not met then the tests fail, resulting in a failed build.

If you are using the Atlassian suite with BitBucket server, then a failed build will prevent a pull request from being merged and prevent changes that drop the code coverage below acceptable thresholds.

Note

I found tools that convert Jest automated tests to Mocha Test Parser format, but was unable to find a tool that converts Jest's code coverage into Mocha Test Parser format. This utility is something custom built that allowed us to implement our code coverage into our Bamboo jobs.

I tried to make it reusable enough to be used across multiple projects and open sourced it so other developers who may also want to use Jest's code coverage in their Bamboo jobs can do. That being said, I know there are opportunities for further configuration and customization available and encourage anyone who makes customizations or configurations to submit a pull request.

Set Up

Install bamboo-jest-mocha-parser in your project:

npm install bamboo-mocha-jest-code-coverage --save-dev

Configure Jest

Make sure you have your Jest code coverage configuration in package.json. By default, Jest outputs code coverage as text, json, and lcov. We will need to add a fourth format: json-summary. The json-summary is what Bamboo Mocha Jest Code Coverage parses for Bamboo's Mocha Test Parser.

Example Jest configuration:

"jest": {
  "collectCoverage": true,
  "coverageDirectory": "coverage",
  "collectCoverageFrom": "app/**/*.jsx",
  "coverageReporters": [
    "text",
    "json",
    "json-summary",
    "lcov"
  ],
  "coverageThreshold": {
    "global": {
      "branches": 100,
      "functions": 100,
      "lines": 90,
      "statements": 100
    }
  }
}

Create NPM Script

Create an NPM script for Bamboo to run that executes Jest and then Bamboo Jest Mocha Parser.

"bamboo:coverage": "jest || true && bamboo-jest-coverage-parser"

NOTE: Jest exits with Exit status 1 if code coverage thresholds are not met. There is currently no way to suppress this or force Jest to exit without Exit status 1.

Exit status 1 causes NPM to abort, meaning if your code coverage does not meet thresholds, Bamboo Mocha Jest Code Coverage will not be executed. Executing jest || true lets the script continue, even if Jest exits with an error.

This introduces risk, as any error will be ignored (not just failed code coverage thresholds). However, until there is a way to suppress Exit status 1 from Jest's code coverage, or a way to format code coverage results like test results, this is the only way to chain the command together for Bamboo.

Configure Bamboo

Now configure a Bamboo job/task that executes the NPM script bamboo:coverage.

After Jest is finished, Bamboo Mocha Jest Code Coverage will convert the summary-json.json file into coverage.json at the root of the project.

Use Bamboo's Mocha Test Parser to parse coverage.json.

Now your test coverage results are available via Bamboo!