Skip to content

Cypress code coverage example when app runs in a Docker container

Notifications You must be signed in to change notification settings

bahmutov/app-in-docker-coverage-example

Repository files navigation

App in Docker, Cypress on Host Machine example

This example requires Docker.

  1. Install dependencies
$ npm install

This will install Cypress and @cypress/code-coverage plugin.

  1. Start local application in local Docker container with
$ npm run docker:start

You will see it mapping the local folder into container-specific path /var/to/my/app/e2e

-v $PWD:/var/to/my/app/e2e -w /var/to/my/app/e2e

The application runs on port 1234 and instruments all source files on the fly with respect to Docker folder /var/to/my/app/e2e.

  1. Run Cypress tests with
$ npm run cy:run

Tests execute, code coverage object is checked to see if the paths in .nyc_output/out.json exist locally. If not, it tries to automatically find how the current working folder matches to the Docker folder and files that $PWD = /var/to/my/app/e2e. You see it from the last debug messages

code-coverage found prefix that matches current folder: /var/to/my/app/e2e +0ms
code-coverage found common folder /var/to/my/app/e2e that matches current working directory /Users/gleb/git/app-in-docker-coverage-example +0ms
code-coverage replaced /var/to/my/app/e2e/app/main.js -> /Users/gleb/git/app-in-docker-coverage-example/app/main.js +0ms
code-coverage replaced /var/to/my/app/e2e/app/second.js -> /Users/gleb/git/app-in-docker-coverage-example/app/second.js +0ms
code-coverage saving updated file /Users/gleb/git/app-in-docker-coverage-example/.nyc_output/out.json +0ms

The report is then generated on the host machine and it has the right files.

~/git/app-in-docker-coverage-example on master
$ open coverage/lcov-report/index.html

All files

One file

About

Cypress code coverage example when app runs in a Docker container

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published