diff --git a/.gitignore b/.gitignore index 1a0d00efd99e..d2a094fa2347 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node-* /plugins /lib/coder-cloud-agent .home +coverage diff --git a/README.md b/README.md index 1d18de5a8290..e3b2bef4a3f2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/ci/README.md b/ci/README.md index 5ef2a2c51738..b261a0ff4385 100644 --- a/ci/README.md +++ b/ci/README.md @@ -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 @@ -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. diff --git a/ci/dev/postinstall.sh b/ci/dev/postinstall.sh index 2ca2e0591614..0ffa772f3ebf 100755 --- a/ci/dev/postinstall.sh +++ b/ci/dev/postinstall.sh @@ -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} diff --git a/ci/dev/test.sh b/ci/dev/test.sh index 5821cb93dba3..6b0acd02aaf7 100755 --- a/ci/dev/test.sh +++ b/ci/dev/test.sh @@ -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 "$@" diff --git a/package.json b/package.json index 1bb8dbf6010e..33310d2c0ddd 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", "@types/parcel-bundler": "^1.12.1", "@types/pem": "^1.9.5", "@types/proxy-from-env": "^1.0.1", @@ -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", @@ -107,5 +108,34 @@ ], "engines": { "node": ">= 12" + }, + "jest": { + "transform": { + "^.+\\.ts$": "/test/node_modules/ts-jest" + }, + "testEnvironment": "node", + "testPathIgnorePatterns": [ + "/node_modules/", + "/lib/vscode", + "/out" + ], + "collectCoverage": true, + "collectCoverageFrom": [ + "/src/**/*.ts" + ], + "coverageDirectory": "/coverage", + "coverageReporters": [ + "json", + "json-summary", + "text" + ], + "coveragePathIgnorePatterns": [ + "out" + ], + "coverageThreshold": { + "global": { + "lines": 40 + } + } } } diff --git a/test/jest.config.js b/test/jest.config.js deleted file mode 100644 index 841e6c2e8576..000000000000 --- a/test/jest.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - preset: "ts-jest", - testEnvironment: "node", - testPathIgnorePatterns: ["/node_modules/", "lib/vscode/"], -} diff --git a/test/package.json b/test/package.json index a40bb5a6a4ff..cbaa08881612 100644 --- a/test/package.json +++ b/test/package.json @@ -1,14 +1,6 @@ { - "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", @@ -16,7 +8,6 @@ "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" } } diff --git a/test/tsconfig.json b/test/tsconfig.json index 20f6bb213d60..5197ce2769f4 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,10 +1,4 @@ { "extends": "../tsconfig.json", - "compilerOptions": { - "typeRoots": ["node_modules/@types", "../typings"], - "composite": true - }, - "include": ["./**/*.ts"], - "exclude": ["node_modules/**"], - "types": ["jest"] + "include": ["./**/*.ts"] } diff --git a/test/yarn.lock b/test/yarn.lock index 1b2fb4c09b4a..148a531a41c0 100644 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -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" diff --git a/tsconfig.json b/tsconfig.json index f37387bf334a..a23926ab0095 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"], "downlevelIteration": true }, "include": ["./src/**/*.ts"], diff --git a/yarn.lock b/yarn.lock index c57ef3a626da..d692116ece16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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== @@ -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" @@ -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"