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

12 files changed

+70
-54
lines changed

Diff for: .gitignore

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

Diff for: README.md

+2
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)

Diff for: ci/README.md

+14
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.

Diff for: ci/dev/postinstall.sh

+5
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

Diff for: ci/dev/test.sh

+5-4
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 "$@"

Diff for: package.json

+32-2
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
}

Diff for: test/jest.config.js

-5
This file was deleted.

Diff for: test/package.json

+3-12
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
}

Diff for: test/tsconfig.json

+1-7
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
}

Diff for: test/yarn.lock

-5
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"

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"sourceMap": true,
1616
"tsBuildInfoFile": "./.cache/tsbuildinfo",
1717
"incremental": true,
18-
"typeRoots": ["./node_modules/@types", "./typings"],
18+
"typeRoots": ["./node_modules/@types", "./typings", "./test/node_modules/@types"],
1919
"downlevelIteration": true
2020
},
2121
"include": ["./src/**/*.ts"],

Diff for: yarn.lock

+6-18
Original file line numberDiff line numberDiff line change
@@ -1098,14 +1098,6 @@
10981098
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
10991099
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
11001100

1101-
"@types/node-fetch@^2.5.7":
1102-
version "2.5.7"
1103-
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
1104-
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
1105-
dependencies:
1106-
"@types/node" "*"
1107-
form-data "^3.0.0"
1108-
11091101
"@types/node@*", "@types/node@^12.12.7":
11101102
version "12.12.67"
11111103
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.67.tgz#4f86badb292e822e3b13730a1f9713ed2377f789"
@@ -2164,7 +2156,7 @@ colorette@^1.2.1:
21642156
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
21652157
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
21662158

2167-
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
2159+
combined-stream@^1.0.6, combined-stream@~1.0.6:
21682160
version "1.0.8"
21692161
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
21702162
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
@@ -3449,15 +3441,6 @@ forever-agent@~0.6.1:
34493441
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
34503442
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
34513443

3452-
form-data@^3.0.0:
3453-
version "3.0.0"
3454-
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
3455-
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
3456-
dependencies:
3457-
asynckit "^0.4.0"
3458-
combined-stream "^1.0.8"
3459-
mime-types "^2.1.12"
3460-
34613444
form-data@~2.3.2:
34623445
version "2.3.3"
34633446
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
@@ -4377,6 +4360,11 @@ isstream@~0.1.2:
43774360
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
43784361
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=
43794362

4363+
istanbul-badges-readme@^1.2.0:
4364+
version "1.2.0"
4365+
resolved "https://registry.yarnpkg.com/istanbul-badges-readme/-/istanbul-badges-readme-1.2.0.tgz#f6dc226fb2ef498b1743ca15ae2dd82ccd3b0c28"
4366+
integrity sha512-7yU9tFbl7IsqlgfFF52G1fj7w2Z2k+UykVrCCIAQ8pnezZIIwxtAD079cIcqsbyCH7gCAALhiW3waHv9C24vrg==
4367+
43804368
js-tokens@^4.0.0:
43814369
version "4.0.0"
43824370
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"

0 commit comments

Comments
 (0)