Generating code coverage report in Jest

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • Appwrite - The Open Source Firebase alternative introduces iOS support
  • Scout APM - Less time debugging, more time building
  • SonarLint - Clean code begins in your IDE with SonarLint
  • javascript-algorithms

    📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

    ‎As a demonstration code for this article, I’m going to use Oleksii Trekhleb’s javascript-algorithms repository. This repo is an awesome set of JavaScript implementations of the most famous algorithms (sorting, search, graphs, math algorithms, etc.) and data structures (heap, stack, queue, etc.), so besides learning how to generate a test coverage report in Jest, you’ll have a chance to learn some interesting JS tips and tricks.

  • nyc

    the Istanbul command line interface

    uncovered part of the code For the coverage report Jest is using Istanbul (https://istanbul.js.org) under the hood, which is a general javascript coverage calculation tool.

  • Appwrite

    Appwrite - The Open Source Firebase alternative introduces iOS support . Appwrite is an open source backend server that helps you build native iOS applications much faster with realtime APIs for authentication, databases, files storage, cloud functions and much more!

  • jest

    Delightful JavaScript Testing.

    module.exports = { // The bail config option can be used here to have Jest stop running tests after // the first failure. bail: false, // Indicates whether each individual test should be reported during the run. verbose: false, // Indicates whether the coverage information should be collected while executing the test collectCoverage: false, // The directory where Jest should output its coverage files. coverageDirectory: './coverage/', // If the test path matches any of the patterns, it will be skipped. testPathIgnorePatterns: ['/node_modules/'], // If the file path matches any of the patterns, coverage information will be skipped. coveragePathIgnorePatterns: ['/node_modules/'], // The pattern Jest uses to detect test files. testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', // This option sets the URL for the jsdom environment. // It is reflected in properties such as location.href. // @see: https://github.com/facebook/jest/issues/6769 testURL: 'http://localhost/', // @see: https://jestjs.io/docs/en/configuration#coveragethreshold-object coverageThreshold: { global: { statements: 100, branches: 95, functions: 100, lines: 100, }, }, };

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts