Skip to content

feat(testing): add code coverage #2621

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 2 commits into from
Jan 25, 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
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
9 changes: 5 additions & 4 deletions ci/dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ set -euo pipefail

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

cd test/test-plugin
make -s out/index.js
cd "$OLDPWD/test"
yarn
yarn test "$@"
# 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"
./test/node_modules/.bin/jest "$@"
}

main "$@"
34 changes: 32 additions & 2 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 @@ -37,7 +38,6 @@
"@types/http-proxy": "^1.17.4",
"@types/js-yaml": "^3.12.3",
"@types/node": "^12.12.7",
"@types/node-fetch": "^2.5.7",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to ./test/package.json.

"@types/parcel-bundler": "^1.12.1",
"@types/pem": "^1.9.5",
"@types/proxy-from-env": "^1.0.1",
Expand All @@ -54,6 +54,7 @@
"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",
"parcel-bundler": "^1.12.4",
"prettier": "^2.0.5",
Expand Down Expand Up @@ -107,5 +108,34 @@
],
"engines": {
"node": ">= 12"
},
"jest": {
"transform": {
"^.+\\.ts$": "<rootDir>/test/node_modules/ts-jest"
},
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/lib/vscode",
"<rootDir>/out"
],
"collectCoverage": true,
"collectCoverageFrom": [
"<rootDir>/src/**/*.ts"
],
"coverageDirectory": "<rootDir>/coverage",
"coverageReporters": [
"json",
"json-summary",
"text"
],
"coveragePathIgnorePatterns": [
"out"
],
"coverageThreshold": {
"global": {
"lines": 40
}
}
}
}
5 changes: 0 additions & 5 deletions test/jest.config.js

This file was deleted.

15 changes: 3 additions & 12 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"#": "We must put jest in a sub-directory otherwise VS Code somehow picks up",
"#": "the types and generates conflicts with mocha.",
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/node-fetch": "^2.5.8",
"@types/supertest": "^2.0.10",
"jest": "^26.6.3",
"node-fetch": "^2.6.1",
"supertest": "^6.1.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
"ts-jest": "^26.4.4"
}
}
8 changes: 1 addition & 7 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"typeRoots": ["node_modules/@types", "../typings"],
"composite": true
},
"include": ["./**/*.ts"],
"exclude": ["node_modules/**"],
"types": ["jest"]
"include": ["./**/*.ts"]
}
5 changes: 0 additions & 5 deletions test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3523,11 +3523,6 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==

union-value@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"sourceMap": true,
"tsBuildInfoFile": "./.cache/tsbuildinfo",
"incremental": true,
"typeRoots": ["./node_modules/@types", "./typings"],
"typeRoots": ["./node_modules/@types", "./typings", "./test/node_modules/@types"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"downlevelIteration": true
},
"include": ["./src/**/*.ts"],
Expand Down
24 changes: 6 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,6 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/node-fetch@^2.5.7":
version "2.5.7"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*", "@types/node@^12.12.7":
version "12.12.67"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.67.tgz#4f86badb292e822e3b13730a1f9713ed2377f789"
Expand Down Expand Up @@ -2164,7 +2156,7 @@ colorette@^1.2.1:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==

combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
Expand Down Expand Up @@ -3449,15 +3441,6 @@ forever-agent@~0.6.1:
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=

form-data@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -4377,6 +4360,11 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=

istanbul-badges-readme@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/istanbul-badges-readme/-/istanbul-badges-readme-1.2.0.tgz#f6dc226fb2ef498b1743ca15ae2dd82ccd3b0c28"
integrity sha512-7yU9tFbl7IsqlgfFF52G1fj7w2Z2k+UykVrCCIAQ8pnezZIIwxtAD079cIcqsbyCH7gCAALhiW3waHv9C24vrg==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down