From c066387c920d030a79f46b6db7e40cc10b657392 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 27 Mar 2020 15:02:35 -0400 Subject: [PATCH 1/4] run ts-example server --- .circleci/config.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + examples/ts-example/package.json | 5 ++++- package-lock.json | 6 +++--- package.json | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e9f123f8c..bca33a058 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -146,6 +146,27 @@ workflows: command: npx nyc report --check-coverage true --lines 100 working_directory: examples/before-all-visit + - cypress/run: + attach-workspace: true + name: example-ts-example + requires: + - cypress/install + # there are no jobs to follow this one + # so no need to save the workspace files (saves time) + no-workspace: true + working_directory: examples/ts-example + start: npm start + wait-on: 'http://localhost:1234' + post-steps: + # store the created coverage report folder + # you can click on it in the CircleCI UI + # to see live static HTML site + - store_artifacts: + path: examples/ts-example/coverage + - run: + command: npm run coverage:check + working_directory: examples/ts-example + - publish: filters: branches: @@ -158,3 +179,4 @@ workflows: - backend coverage - example-before-each-visit - example-before-all-visit + - example-ts-example diff --git a/.gitignore b/.gitignore index f1a4f3c45..8e5b13686 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist/ cypress-coverage/ examples/*/cypress/videos examples/*/cypress/screenshots +yarn.lock diff --git a/examples/ts-example/package.json b/examples/ts-example/package.json index 02d50a5de..3f296f798 100644 --- a/examples/ts-example/package.json +++ b/examples/ts-example/package.json @@ -1,7 +1,9 @@ { "name": "example-before-each-visit", "description": "Getting code coverage when cy.visit is used in beforeEach hook", - "devDependencies": {}, + "devDependencies": { + "@babel/core": "7.9.0" + }, "nyc": { "extends": "@istanbuljs/nyc-config-typescript", "all": true @@ -12,6 +14,7 @@ "serve": "../../node_modules/.bin/serve dist", "cy:open": "../../node_modules/.bin/cypress open", "coverage": "../../node_modules/.bin/nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=lcov", + "coverage:check": "../../node_modules/.bin/nyc report --check-coverage true --lines 100", "dev": "../../node_modules/.bin/start-test 1234 cy:open", "dev:dist": "CYPRESS_baseUrl=http://localhost:5000 ../../node_modules/.bin/start-test serve 5000 cy:open" } diff --git a/package-lock.json b/package-lock.json index e5513b180..ef4be7945 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16007,9 +16007,9 @@ } }, "source-map-support": { - "version": "0.5.13", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz", - "integrity": "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==", + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz", + "integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==", "dev": true, "requires": { "buffer-from": "^1.0.0", diff --git a/package.json b/package.json index 0a219be3f..a833b4ea3 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "prettier": "1.19.1", "semantic-release": "17.0.4", "serve": "11.3.0", + "source-map-support": "0.5.16", "start-server-and-test": "1.10.11", "typescript": "3.8.3" } From df1dcab911ec697a35a74d1b72b13ea9abd1901d Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 27 Mar 2020 15:14:15 -0400 Subject: [PATCH 2/4] update README file --- README.md | 46 ++++------------------------------------------ 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 6fcb1690e..1c6df842b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ npm install -D @cypress/code-coverage and its peer dependencies ```shell -npm install -D nyc istanbul-lib-coverage cypress +npm install -D istanbul-lib-coverage cypress ``` Add to your `cypress/support/index.js` file @@ -181,17 +181,6 @@ You can specify custom coverage reporter(s) to use. For example to output text s **Tip:** find list of reporters [here](https://istanbul.js.org/docs/advanced/alternative-reporters/) -## NYC - -This module tries to find the `nyc` tool using [bin-up][bin-up], so it would be found in the current `node_modules/.bin` or folders up the parent chain - -```text -node_modules/.bin/ -../node_modules/.bin/ -../../node_modules/.bin/ -etc -``` - ## Custom NYC command Sometimes NYC tool might be installed in a different folder not in the current or parent folder, or you might want to customize the report command. In that case, put the custom command into `package.json` in the current folder and this plugin will automatically use it. @@ -204,34 +193,6 @@ Sometimes NYC tool might be installed in a different folder not in the current o } ``` -See examples below. - -### Install NYC on the fly - -The simplest solution: let `npx` install `nyc` on the fly - -```json -{ - "scripts": { - "coverage:report": "npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=lcov --reporter=clover --reporter=json" - } -} -``` - -### Find NYC in a parent folder - -If you have [bin-up][bin-up] installed globally, you can use it to find `nyc` installed somewhere in the higher folder. - -```json -{ - "scripts": { - "coverage:report": "bin-up nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=lcov --reporter=clover --reporter=json" - } -} -``` - -**Tip:** finding and running pre-installed tool is always faster than installing it again and again. - ## TypeScript users TypeScript source files are NOT included in the code coverage report by default, even if they are properly instrumented. In order to tell `nyc` to include TS files in the report, you need to: @@ -239,7 +200,7 @@ TypeScript source files are NOT included in the code coverage report by default, 1. Add these dev dependencies that let Istanbul work with TypeScript ```shell -npm i -D @istanbuljs/nyc-config-typescript source-map-support ts-node +npm i -D @istanbuljs/nyc-config-typescript source-map-support ``` 2. In `package.json` use the following `nyc` configuration object @@ -253,6 +214,8 @@ npm i -D @istanbuljs/nyc-config-typescript source-map-support ts-node } ``` +See [examples/ts-example](examples/ts-example) + ## Exclude code You can exclude parts of the code or entire files from the code coverage report. See [Istanbul guide](https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md). Common cases: @@ -393,4 +356,3 @@ This project is licensed under the terms of the [MIT license](LICENSE.md). [renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg [renovate-app]: https://renovateapp.com/ -[bin-up]: https://github.com/bahmutov/bin-up From 0101cc1a916724f7213a823905f412bda58d4328 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 27 Mar 2020 15:27:13 -0400 Subject: [PATCH 3/4] use command --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index bca33a058..a097f80c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -157,6 +157,7 @@ workflows: working_directory: examples/ts-example start: npm start wait-on: 'http://localhost:1234' + command: '../../node_modules/.bin/cypress run' post-steps: # store the created coverage report folder # you can click on it in the CircleCI UI From 3eb6153da5d032ad864c8054d88e80ebb835d6f2 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 27 Mar 2020 16:12:33 -0400 Subject: [PATCH 4/4] feat: move istanbul-lib-coverage from peer to prod dependencies --- README.md | 6 +----- package-lock.json | 3 +-- package.json | 7 +++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1c6df842b..a76e16d64 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,7 @@ This plugin will slow down your tests. There will be more web application JavaSc npm install -D @cypress/code-coverage ``` -and its peer dependencies - -```shell -npm install -D istanbul-lib-coverage cypress -``` +Note: this plugin assumes `cypress` is a peer dependency already installed in your project. Add to your `cypress/support/index.js` file diff --git a/package-lock.json b/package-lock.json index ef4be7945..660776199 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8293,8 +8293,7 @@ "istanbul-lib-coverage": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.0.0.tgz", - "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==", - "dev": true + "integrity": "sha512-UiUIqxMgRDET6eR+o5HbfRYP1l0hqkWOs7vNxC/mggutCMUIhWMm8gAHb8tHlyfD3/l6rlgNA5cKdDzEAf6hEg==" }, "istanbul-lib-hook": { "version": "3.0.0", diff --git a/package.json b/package.json index a833b4ea3..5a4b89997 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,7 @@ "effective:config": "circleci config process .circleci/config.yml | sed /^#/d" }, "peerDependencies": { - "cypress": "*", - "istanbul-lib-coverage": "*" + "cypress": "*" }, "repository": { "type": "git", @@ -53,7 +52,8 @@ "@cypress/browserify-preprocessor": "2.1.4", "debug": "4.1.1", "execa": "4.0.0", - "nyc": "15.0.0" + "nyc": "15.0.0", + "istanbul-lib-coverage": "3.0.0" }, "devDependencies": { "@babel/core": "7.9.0", @@ -61,7 +61,6 @@ "babel-plugin-istanbul": "6.0.0", "cypress": "4.2.0", "express": "4.17.1", - "istanbul-lib-coverage": "3.0.0", "lodash": "4.17.15", "markdown-link-check": "3.8.0", "parcel-bundler": "1.12.4",