Skip to content

refactor(tests): migrate from mocha to jest #2564

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 14 commits into from
Jan 26, 2021
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
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parser: "@typescript-eslint/parser"
env:
browser: true
es6: true # Map, etc.
mocha: true
jest: true
node: true

parserOptions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ node-*
/plugins
/lib/coder-cloud-agent
.home
coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 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)

![Lines](https://img.shields.io/badge/Coverage-46.71%25-green.svg)

Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and access it in the browser.

![Screenshot](./doc/assets/screenshot.png)
Expand Down
14 changes: 14 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub)
- Remember to update the chart version as well on top of appVersion in `Chart.yaml`.
- Run `rg -g '!yarn.lock' -g '!*.svg' '3\.7\.5'` to ensure all values have been
changed. Replace the numbers as needed.
4. Update the code coverage badge (see [here](#updating-code-coverage-in-readme) for instructions)
2. GitHub actions will generate the `npm-package`, `release-packages` and `release-images` artifacts.
1. You do not have to wait for these.
3. Run `yarn release:github-draft` to create a GitHub draft release from the template with
Expand All @@ -43,6 +44,19 @@ Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub)
11. Update the homebrew package.
- 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.

## Updating Code Coverage in README

Currently, we run a command to manually generate the code coverage shield. Follow these steps:

1. Run `yarn badges`
2. Go into the README and change the color from `red` to `green` in this line:

```
![Lines](https://img.shields.io/badge/Coverage-46.71%25-red.svg)
```

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).

## dev

This directory contains scripts used for the development of code-server.
Expand Down
5 changes: 5 additions & 0 deletions ci/dev/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ main() {
cd "$(dirname "$0")/../.."
source ./ci/lib.sh

# This installs the dependencies needed for testing
cd test
yarn
cd ..

cd lib/vscode
yarn ${CI+--frozen-lockfile}

Expand Down
6 changes: 4 additions & 2 deletions ci/dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ set -euo pipefail

main() {
cd "$(dirname "$0")/../.."

cd test/test-plugin
make -s out/index.js
# We must keep jest in a sub-directory. See ../../test/package.json for more
# information. We must also run it from the root otherwise coverage will not
# include our source files.
cd "$OLDPWD"
mocha -r ts-node/register ./test/*.test.ts "$@"
./test/node_modules/.bin/jest "$@"
}

main "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import * as vscode from 'vscode';

export function isWeb(): boolean {
// NOTE@coder: Remove unused ts-expect-error directive which causes tsc to error.
// @ts-expect-error
return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web;
}
38 changes: 33 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"test": "./ci/dev/test.sh",
"ci": "./ci/dev/ci.sh",
"watch": "VSCODE_IPC_HOOK_CLI= NODE_OPTIONS=--max_old_space_size=32384 ts-node ./ci/dev/watch.ts",
"icons": "./ci/dev/gen_icons.sh"
"icons": "./ci/dev/gen_icons.sh",
"badges": "istanbul-badges-readme"
},
"main": "out/node/entry.js",
"devDependencies": {
Expand All @@ -36,9 +37,7 @@
"@types/fs-extra": "^8.0.1",
"@types/http-proxy": "^1.17.4",
"@types/js-yaml": "^3.12.3",
"@types/mocha": "^8.0.3",
"@types/node": "^12.12.7",
"@types/node-fetch": "^2.5.7",
"@types/parcel-bundler": "^1.12.1",
"@types/pem": "^1.9.5",
"@types/proxy-from-env": "^1.0.1",
Expand All @@ -55,14 +54,14 @@
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0",
"istanbul-badges-readme": "^1.2.0",
"leaked-handles": "^5.2.0",
"mocha": "^8.1.2",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.5",
"stylelint": "^13.0.0",
"stylelint-config-recommended": "^3.0.0",
"ts-node": "^9.0.0",
"typescript": "4.0.2"
"typescript": "^4.1.3"
},
"resolutions": {
"@types/node": "^12.12.7",
Expand Down Expand Up @@ -109,5 +108,34 @@
],
"engines": {
"node": ">= 12"
},
"jest": {
"transform": {
"^.+\\.ts$": "<rootDir>/test/node_modules/ts-jest"
},
"testEnvironment": "node",
"testPathIgnorePatterns": [
"node_modules",
"lib",
"out"
],
"collectCoverage": true,
"collectCoverageFrom": [
"<rootDir>/src/**/*.ts"
],
"coverageDirectory": "<rootDir>/coverage",
"coverageReporters": [
"json",
"json-summary",
"text"
],
"coveragePathIgnorePatterns": [
"out"
],
"coverageThreshold": {
"global": {
"lines": 40
}
}
}
}
2 changes: 1 addition & 1 deletion src/node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express,
: http.createServer(app)

let resolved = false
await new Promise<http.Server>(async (resolve2, reject) => {
await new Promise<void>(async (resolve2, reject) => {
const resolve = () => {
resolved = true
resolve2()
Expand Down
2 changes: 1 addition & 1 deletion src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const open = async (url: string): Promise<void> => {
url = url.replace(/&/g, "^&")
}
const proc = cp.spawn(command, [...args, url], options)
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
proc.on("error", reject)
proc.on("close", (code) => {
return code !== 0 ? reject(new Error(`Failed to open with code ${code}`)) : resolve()
Expand Down
Loading