Skip to content

Commit bdb8b0e

Browse files
authored
Merge pull request #2621 from cdr/issue-2550-add-coverage
feat(testing): add code coverage
2 parents 883dd13 + ac127f6 commit bdb8b0e

File tree

12 files changed

+70
-54
lines changed

12 files changed

+70
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ node-*
1414
/plugins
1515
/lib/coder-cloud-agent
1616
.home
17+
coverage

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# code-server · [!["GitHub Discussions"](https://img.shields.io/badge/%20GitHub-%20Discussions-gray.svg?longCache=true&logo=github&colorB=purple)](https://github.com/cdr/code-server/discussions) [!["Join us on Slack"](https://img.shields.io/badge/join-us%20on%20slack-gray.svg?longCache=true&logo=slack&colorB=brightgreen)](https://cdr.co/join-community) [![Twitter Follow](https://img.shields.io/twitter/follow/CoderHQ?label=%40CoderHQ&style=social)](https://twitter.com/coderhq)
22

3+
![Lines](https://img.shields.io/badge/Coverage-46.71%25-green.svg)
4+
35
Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and access it in the browser.
46

57
![Screenshot](./doc/assets/screenshot.png)

ci/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub)
2121
- Remember to update the chart version as well on top of appVersion in `Chart.yaml`.
2222
- Run `rg -g '!yarn.lock' -g '!*.svg' '3\.7\.5'` to ensure all values have been
2323
changed. Replace the numbers as needed.
24+
4. Update the code coverage badge (see [here](#updating-code-coverage-in-readme) for instructions)
2425
2. GitHub actions will generate the `npm-package`, `release-packages` and `release-images` artifacts.
2526
1. You do not have to wait for these.
2627
3. Run `yarn release:github-draft` to create a GitHub draft release from the template with
@@ -43,6 +44,19 @@ Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub)
4344
11. Update the homebrew package.
4445
- Send a pull request to [homebrew-core](https://github.com/Homebrew/homebrew-core) with the URL in the [formula](https://github.com/Homebrew/homebrew-core/blob/master/Formula/code-server.rb) updated.
4546

47+
## Updating Code Coverage in README
48+
49+
Currently, we run a command to manually generate the code coverage shield. Follow these steps:
50+
51+
1. Run `yarn badges`
52+
2. Go into the README and change the color from `red` to `green` in this line:
53+
54+
```
55+
![Lines](https://img.shields.io/badge/Coverage-46.71%25-red.svg)
56+
```
57+
58+
NOTE: we have to manually change the color because the default is red if coverage is less than 80. See code [here](https://github.com/olavoparno/istanbul-badges-readme/blob/develop/src/editor.ts#L24-L33).
59+
4660
## dev
4761

4862
This directory contains scripts used for the development of code-server.

ci/dev/postinstall.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ main() {
55
cd "$(dirname "$0")/../.."
66
source ./ci/lib.sh
77

8+
# This installs the dependencies needed for testing
9+
cd test
10+
yarn
11+
cd ..
12+
813
cd lib/vscode
914
yarn ${CI+--frozen-lockfile}
1015

ci/dev/test.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
76
cd test/test-plugin
87
make -s out/index.js
9-
cd "$OLDPWD/test"
10-
yarn
11-
yarn test "$@"
8+
# We must keep jest in a sub-directory. See ../../test/package.json for more
9+
# information. We must also run it from the root otherwise coverage will not
10+
# include our source files.
11+
cd "$OLDPWD"
12+
./test/node_modules/.bin/jest "$@"
1213
}
1314

1415
main "$@"

package.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"test": "./ci/dev/test.sh",
2727
"ci": "./ci/dev/ci.sh",
2828
"watch": "VSCODE_IPC_HOOK_CLI= NODE_OPTIONS=--max_old_space_size=32384 ts-node ./ci/dev/watch.ts",
29-
"icons": "./ci/dev/gen_icons.sh"
29+
"icons": "./ci/dev/gen_icons.sh",
30+
"badges": "istanbul-badges-readme"
3031
},
3132
"main": "out/node/entry.js",
3233
"devDependencies": {
@@ -37,7 +38,6 @@
3738
"@types/http-proxy": "^1.17.4",
3839
"@types/js-yaml": "^3.12.3",
3940
"@types/node": "^12.12.7",
40-
"@types/node-fetch": "^2.5.7",
4141
"@types/parcel-bundler": "^1.12.1",
4242
"@types/pem": "^1.9.5",
4343
"@types/proxy-from-env": "^1.0.1",
@@ -54,6 +54,7 @@
5454
"eslint-config-prettier": "^6.0.0",
5555
"eslint-plugin-import": "^2.18.2",
5656
"eslint-plugin-prettier": "^3.1.0",
57+
"istanbul-badges-readme": "^1.2.0",
5758
"leaked-handles": "^5.2.0",
5859
"parcel-bundler": "^1.12.4",
5960
"prettier": "^2.0.5",
@@ -107,5 +108,34 @@
107108
],
108109
"engines": {
109110
"node": ">= 12"
111+
},
112+
"jest": {
113+
"transform": {
114+
"^.+\\.ts$": "<rootDir>/test/node_modules/ts-jest"
115+
},
116+
"testEnvironment": "node",
117+
"testPathIgnorePatterns": [
118+
"/node_modules/",
119+
"<rootDir>/lib/vscode",
120+
"<rootDir>/out"
121+
],
122+
"collectCoverage": true,
123+
"collectCoverageFrom": [
124+
"<rootDir>/src/**/*.ts"
125+
],
126+
"coverageDirectory": "<rootDir>/coverage",
127+
"coverageReporters": [
128+
"json",
129+
"json-summary",
130+
"text"
131+
],
132+
"coveragePathIgnorePatterns": [
133+
"out"
134+
],
135+
"coverageThreshold": {
136+
"global": {
137+
"lines": 40
138+
}
139+
}
110140
}
111141
}

test/jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
{
2-
"name": "test",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "jest"
8-
},
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
2+
"#": "We must put jest in a sub-directory otherwise VS Code somehow picks up",
3+
"#": "the types and generates conflicts with mocha.",
124
"devDependencies": {
135
"@types/jest": "^26.0.20",
146
"@types/node-fetch": "^2.5.8",
157
"@types/supertest": "^2.0.10",
168
"jest": "^26.6.3",
179
"node-fetch": "^2.6.1",
1810
"supertest": "^6.1.1",
19-
"ts-jest": "^26.4.4",
20-
"typescript": "^4.1.3"
11+
"ts-jest": "^26.4.4"
2112
}
2213
}

test/tsconfig.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
22
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"typeRoots": ["node_modules/@types", "../typings"],
5-
"composite": true
6-
},
7-
"include": ["./**/*.ts"],
8-
"exclude": ["node_modules/**"],
9-
"types": ["jest"]
3+
"include": ["./**/*.ts"]
104
}

test/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,11 +3523,6 @@ typedarray-to-buffer@^3.1.5:
35233523
dependencies:
35243524
is-typedarray "^1.0.0"
35253525

3526-
typescript@^4.1.3:
3527-
version "4.1.3"
3528-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
3529-
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
3530-
35313526
union-value@^1.0.0:
35323527
version "1.0.1"
35333528
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"

0 commit comments

Comments
 (0)