Skip to content

Commit fa548e9

Browse files
authored
Merge pull request #2564 from cdr/issue-2550-migrate-mocha-jest
refactor(tests): migrate from mocha to jest
2 parents c52198f + 102f51c commit fa548e9

20 files changed

+4036
-609
lines changed

Diff for: .eslintrc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ parser: "@typescript-eslint/parser"
22
env:
33
browser: true
44
es6: true # Map, etc.
5-
mocha: true
5+
jest: true
66
node: true
77

88
parserOptions:

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
76
cd test/test-plugin
87
make -s out/index.js
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.
911
cd "$OLDPWD"
10-
mocha -r ts-node/register ./test/*.test.ts "$@"
12+
./test/node_modules/.bin/jest "$@"
1113
}
1214

1315
main "$@"

Diff for: lib/vscode/extensions/typescript-language-features/src/utils/platform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
import * as vscode from 'vscode';
77

88
export function isWeb(): boolean {
9-
// NOTE@coder: Remove unused ts-expect-error directive which causes tsc to error.
9+
// @ts-expect-error
1010
return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web;
1111
}

Diff for: package.json

+33-5
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": {
@@ -36,9 +37,7 @@
3637
"@types/fs-extra": "^8.0.1",
3738
"@types/http-proxy": "^1.17.4",
3839
"@types/js-yaml": "^3.12.3",
39-
"@types/mocha": "^8.0.3",
4040
"@types/node": "^12.12.7",
41-
"@types/node-fetch": "^2.5.7",
4241
"@types/parcel-bundler": "^1.12.1",
4342
"@types/pem": "^1.9.5",
4443
"@types/proxy-from-env": "^1.0.1",
@@ -55,14 +54,14 @@
5554
"eslint-config-prettier": "^6.0.0",
5655
"eslint-plugin-import": "^2.18.2",
5756
"eslint-plugin-prettier": "^3.1.0",
57+
"istanbul-badges-readme": "^1.2.0",
5858
"leaked-handles": "^5.2.0",
59-
"mocha": "^8.1.2",
6059
"parcel-bundler": "^1.12.4",
6160
"prettier": "^2.0.5",
6261
"stylelint": "^13.0.0",
6362
"stylelint-config-recommended": "^3.0.0",
6463
"ts-node": "^9.0.0",
65-
"typescript": "4.0.2"
64+
"typescript": "^4.1.3"
6665
},
6766
"resolutions": {
6867
"@types/node": "^12.12.7",
@@ -109,5 +108,34 @@
109108
],
110109
"engines": {
111110
"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+
"lib",
120+
"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+
}
112140
}
113141
}

Diff for: src/node/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express,
2424
: http.createServer(app)
2525

2626
let resolved = false
27-
await new Promise<http.Server>(async (resolve2, reject) => {
27+
await new Promise<void>(async (resolve2, reject) => {
2828
const resolve = () => {
2929
resolved = true
3030
resolve2()

Diff for: src/node/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const open = async (url: string): Promise<void> => {
187187
url = url.replace(/&/g, "^&")
188188
}
189189
const proc = cp.spawn(command, [...args, url], options)
190-
await new Promise((resolve, reject) => {
190+
await new Promise<void>((resolve, reject) => {
191191
proc.on("error", reject)
192192
proc.on("close", (code) => {
193193
return code !== 0 ? reject(new Error(`Failed to open with code ${code}`)) : resolve()

0 commit comments

Comments
 (0)