Skip to content

Commit 05beccf

Browse files
committed
refactor: move jest around and add code coverage
1 parent 883dd13 commit 05beccf

10 files changed

+40
-53
lines changed

.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

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

ci/dev/test.sh

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

44
main() {
55
cd "$(dirname "$0")/../.."
6-
76
cd test/test-plugin
87
make -s out/index.js
9-
cd "$OLDPWD/test"
10-
yarn
11-
yarn test "$@"
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.
11+
cd "$OLDPWD"
12+
./test/node_modules/.bin/jest "$@"
1213
}
1314

1415
main "$@"

package.json

+23-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@types/http-proxy": "^1.17.4",
3838
"@types/js-yaml": "^3.12.3",
3939
"@types/node": "^12.12.7",
40-
"@types/node-fetch": "^2.5.7",
4140
"@types/parcel-bundler": "^1.12.1",
4241
"@types/pem": "^1.9.5",
4342
"@types/proxy-from-env": "^1.0.1",
@@ -107,5 +106,28 @@
107106
],
108107
"engines": {
109108
"node": ">= 12"
109+
},
110+
"jest": {
111+
"transform": {
112+
"^.+\\.ts$": "<rootDir>/test/node_modules/ts-jest"
113+
},
114+
"testEnvironment": "node",
115+
"testPathIgnorePatterns": [
116+
"/node_modules/",
117+
"<rootDir>/lib/vscode",
118+
"<rootDir>/out"
119+
],
120+
"collectCoverage": true,
121+
"collectCoverageFrom": [
122+
"<rootDir>/src/**/*.ts"
123+
],
124+
"coverageDirectory": "<rootDir>/coverage",
125+
"coverageReporters": [
126+
"json",
127+
"text"
128+
],
129+
"coveragePathIgnorePatterns": [
130+
"out"
131+
]
110132
}
111133
}

test/jest.config.js

-5
This file was deleted.

test/package.json

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
{
2-
"name": "test",
3-
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "jest"
8-
},
9-
"keywords": [],
10-
"author": "",
11-
"license": "ISC",
2+
"#": "We must put jest in a sub-directory otherwise VS Code somehow picks up",
3+
"#": "the types and generates conflicts with mocha.",
124
"devDependencies": {
135
"@types/jest": "^26.0.20",
146
"@types/node-fetch": "^2.5.8",
157
"@types/supertest": "^2.0.10",
168
"jest": "^26.6.3",
179
"node-fetch": "^2.6.1",
1810
"supertest": "^6.1.1",
19-
"ts-jest": "^26.4.4",
20-
"typescript": "^4.1.3"
11+
"ts-jest": "^26.4.4"
2112
}
2213
}

test/tsconfig.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
{
22
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"typeRoots": ["node_modules/@types", "../typings"],
5-
"composite": true
6-
},
7-
"include": ["./**/*.ts"],
8-
"exclude": ["node_modules/**"],
9-
"types": ["jest"]
3+
"include": ["./**/*.ts"]
104
}

test/yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -3523,11 +3523,6 @@ typedarray-to-buffer@^3.1.5:
35233523
dependencies:
35243524
is-typedarray "^1.0.0"
35253525

3526-
typescript@^4.1.3:
3527-
version "4.1.3"
3528-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
3529-
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
3530-
35313526
union-value@^1.0.0:
35323527
version "1.0.1"
35333528
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"sourceMap": true,
1616
"tsBuildInfoFile": "./.cache/tsbuildinfo",
1717
"incremental": true,
18-
"typeRoots": ["./node_modules/@types", "./typings"],
18+
"typeRoots": ["./node_modules/@types", "./typings", "./test/node_modules/@types"],
1919
"downlevelIteration": true
2020
},
2121
"include": ["./src/**/*.ts"],

yarn.lock

+1-18
Original file line numberDiff line numberDiff line change
@@ -1098,14 +1098,6 @@
10981098
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
10991099
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=
11001100

1101-
"@types/node-fetch@^2.5.7":
1102-
version "2.5.7"
1103-
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
1104-
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
1105-
dependencies:
1106-
"@types/node" "*"
1107-
form-data "^3.0.0"
1108-
11091101
"@types/node@*", "@types/node@^12.12.7":
11101102
version "12.12.67"
11111103
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.67.tgz#4f86badb292e822e3b13730a1f9713ed2377f789"
@@ -2164,7 +2156,7 @@ colorette@^1.2.1:
21642156
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
21652157
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
21662158

2167-
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
2159+
combined-stream@^1.0.6, combined-stream@~1.0.6:
21682160
version "1.0.8"
21692161
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
21702162
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
@@ -3449,15 +3441,6 @@ forever-agent@~0.6.1:
34493441
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
34503442
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
34513443

3452-
form-data@^3.0.0:
3453-
version "3.0.0"
3454-
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
3455-
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
3456-
dependencies:
3457-
asynckit "^0.4.0"
3458-
combined-stream "^1.0.8"
3459-
mime-types "^2.1.12"
3460-
34613444
form-data@~2.3.2:
34623445
version "2.3.3"
34633446
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"

0 commit comments

Comments
 (0)