Collecting Code Coverage from Webpack Dev Server for Cypress.io Tests

This example demonstrates how to collect code coverage from a Webpack development server for Cypress.io tests. Follow the steps below to set up and run the coverage:

  1. Install the Webpack Dev Server: Start by installing and launching the Webpack development server. Run the following commands:

    bash

    npm ci

    npm start

    This will open the server at localhost:8080.

  2. Set up Code Coverage: To enable code coverage detection for both end-to-end (E2E) tests and unit tests, configure the application source code using Webpack + Babel. Ensure NODE_ENV=test is enabled in your environment.

  3. Running Cypress Tests: To execute Cypress and collect coverage:

  4. Launch the dev server: npm run dev
  5. Run the tests: npm run e2e

    You can observe the coverage data through the window.__coverage__ object in the application iframe.

  6. Unit Testing: If you prefer loading the application’s JavaScript directly from the spec file instead of using the dev server, modify your test setup accordingly.

These steps will help you gather comprehensive code coverage while running your tests in Cypress on a Webpack development server.

zip 文件大小:1.07MB