Skip to content

fix: simpler TypeScript advice #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ workflows:
name: Check code coverage 📈
command: |
../../node_modules/.bin/check-coverage main.ts
../../node_modules/.bin/only-covered main.ts
../../node_modules/.bin/check-coverage calc.ts
../../node_modules/.bin/only-covered main.ts calc.ts
working_directory: examples/ts-example

- cypress/run:
Expand Down
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ labels: ''
assignees: ''
---

**Logs and screenshots**
Please provide debug logs by running Cypress from the terminal with `DEBUG=code-coverage` environment variable set, see the [Debugging](https://github.com/cypress-io/code-coverage#debugging) section of the README file.

**Versions**

- What is this plugin's version?
Expand All @@ -21,8 +24,5 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.

**Logs and screenshots**
If possible, add the log from the terminal. You can turn on debugging logging, see [Debugging](https://github.com/cypress-io/code-coverage#debugging) section of the README file.

**Link to the repo**
Bugs with a reproducible example, like an open source repo showing the bug, are the most likely to be resolved.
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,9 @@ Sometimes NYC tool might be installed in a different folder not in the current o

## 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:
TypeScript source files should be automatically included in the report, if they are instrumented.

1. Add these dev dependencies that let Istanbul work with TypeScript

```shell
npm i -D @istanbuljs/nyc-config-typescript source-map-support
```

2. In `package.json` use the following `nyc` configuration object

```json
{
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"all": true
}
}
```

See [examples/ts-example](examples/ts-example)
See [examples/ts-example](examples/ts-example) and [bahmutov/cra-ts-code-coverage-example](https://github.com/bahmutov/cra-ts-code-coverage-example).

## Exclude code

Expand Down Expand Up @@ -413,6 +396,8 @@ npx nyc report --check-coverage true --lines 100 --include cypress/about.js
npx nyc report --check-coverage true --lines 100 --include cypress/unit.js
```

**Tip:** use [check-code-coverage](https://github.com/bahmutov/check-code-coverage) for stricter code coverage checks than `nyc report --check-coverage` allows.

### Markdown

You can validate links in Markdown files in this directory by executing (Linux + Mac only) script
Expand Down
3 changes: 3 additions & 0 deletions examples/ts-example/calc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const add = (a: number, b: number) => {
return a + b
}
4 changes: 1 addition & 3 deletions examples/ts-example/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const add = (a: number, b: number) => {
return a + b
}
import { add } from './calc'

const sub = (a: number, b: number) => {
return a - b
Expand Down
4 changes: 0 additions & 4 deletions examples/ts-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"devDependencies": {
"@babel/core": "7.9.0"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"all": true
},
"scripts": {
"start": "../../node_modules/.bin/parcel serve index.html",
"build": "../../node_modules/.bin/parcel build index.html",
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
},
"devDependencies": {
"@babel/core": "7.9.0",
"@istanbuljs/nyc-config-typescript": "1.0.1",
"babel-plugin-istanbul": "6.0.0",
"check-code-coverage": "1.0.1",
"cypress": "4.3.0",
Expand All @@ -65,7 +64,6 @@
"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"
}
Expand Down
10 changes: 9 additions & 1 deletion task.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const tasks = {
// I am mostly worried about additional NYC options that are stored in
// package.json and .nycrc resource files.
// for now let's just camel case all options
// https://github.com/istanbuljs/nyc#common-configuration-options
const nycReportOptions = {
reportDir,
tempDir: coverageFolder,
Expand All @@ -156,7 +157,14 @@ const tasks = {
exclude: nycOptions.exclude,
// from working with TypeScript code seems we need these settings too
excludeAfterRemap: true,
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
extension: nycOptions.extension || [
'.js',
'.cjs',
'.mjs',
'.ts',
'.tsx',
'.jsx'
],
all: nycOptions.all
}

Expand Down