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:
-
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.
-
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. -
Running Cypress Tests: To execute Cypress and collect coverage:
- Launch the dev server:
npm run dev
-
Run the tests: npm run e2e
You can observe the coverage data through the window.__coverage__ object in the application iframe.
-
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.
评论区