From 05beccf671b0c9eae5c8d499336a20fe7efe4957 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 21 Jan 2021 16:39:04 -0700 Subject: [PATCH] refactor: move jest around and add code coverage --- .gitignore | 1 + ci/dev/postinstall.sh | 5 +++++ ci/dev/test.sh | 9 +++++---- package.json | 24 +++++++++++++++++++++++- test/jest.config.js | 5 ----- test/package.json | 15 +++------------ test/tsconfig.json | 8 +------- test/yarn.lock | 5 ----- tsconfig.json | 2 +- yarn.lock | 19 +------------------ 10 files changed, 40 insertions(+), 53 deletions(-) delete mode 100644 test/jest.config.js diff --git a/.gitignore b/.gitignore index 1a0d00ef..d2a094fa 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node-* /plugins /lib/coder-cloud-agent .home +coverage diff --git a/ci/dev/postinstall.sh b/ci/dev/postinstall.sh index 2ca2e059..0ffa772f 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 5821cb93..6b0acd02 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 1bb8dbf6..a432acab 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,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", @@ -107,5 +106,28 @@ ], "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", + "text" + ], + "coveragePathIgnorePatterns": [ + "out" + ] } } diff --git a/test/jest.config.js b/test/jest.config.js deleted file mode 100644 index 841e6c2e..00000000 --- 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 a40bb5a6..cbaa0888 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 20f6bb21..5197ce27 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 1b2fb4c0..148a531a 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 f37387bf..a23926ab 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 c57ef3a6..618121a7 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"