JSPM

cypress-code-coverage-v8

1.0.6
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 735
  • Score
    100M100P100Q103999F
  • License MIT

Saves the code coverage collected during Cypress tests using V8

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cypress-code-coverage-v8) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    cypress-code-coverage-v8

    Collects code coverage of your application under test using V8's built in JavaScript code coverage. No need to instrument your application!

    Install

    npm install -D cypress-code-coverage-v8

    Note: This plugin assumes that cypress is a peer dependency already installed in your project.

    Then add the code below to the supportFile and setupNodeEvents function.

    // cypress/support/e2e.{js|ts}
    import "cypress-code-coverage-v8/support";
    // cypress.config.{js|ts}
    import { defineConfig } from "cypress";
    import cypressV8Coverage from "cypress-code-coverage-v8/task";
    
    export default defineConfig({
      e2e: {
        setupNodeEvents(on, config) {
          cypressV8Coverage(on, config);
          // include any other plugin code...
    
          // It's IMPORTANT to return the config object here
          return config;
        },
    
        baseUrl: "http://localhost:5173/",
      },
    });

    Next, run your Cypress tests with coverage enabled. Note: it must be run within Chrome.

    CYPRESS_COVERAGE=true npx cypress run --browser chrome

    Then you can generate the coverage report using nyc.

    npx nyc report --reporter=text --reporter=text-summary --reporter=html --temp-dir=cypress-coverage --report-dir=cypress-coverage-reports

    Examples

    Check out the examples in the test-apps directory to see how this might work for your type of application.

    V8 Coverage vs Istanbul?

    There are some trade-offs associated with taking Coverage using V8's native system vs Istanbul. Please give the above a read and make your own decision on whether or not it is worth it for you.

    How it works

    1. It takes V8 coverage directly from the the V8 engine while Cypress tests are running

    2. After each test, it looks at the V8 coverage object and finds all files served from the application’s URL

    3. it takes built source files and finds their corresponding sourcemap files .map

    4. the sourcemap files are parsed to find all the source .ts and .tsx files which were loaded and ran by the V8 engine

    5. we also find all the files which were NOT loaded by the V8 engine and create dummy coverage files for them, allowing us to get a full view of the coverage of our application. these will have 0% coverage in the final report

    6. these files, along with the V8 coverage are then converted to the Istanbul coverage format

    7. from there, it is easy to use existing cli tools like nyc to convert these istanbul coverage JSON objects into html, text, coburtura, etc, report styles

    Acknowledgements