Skip to content

Commit 73a8fda

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

File tree

8 files changed

+39
-36
lines changed

8 files changed

+39
-36
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/test.sh

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

44
main() {
55
cd "$(dirname "$0")/../.."
6-
7-
cd test/test-plugin
8-
make -s out/index.js
9-
cd "$OLDPWD/test"
6+
cd test
7+
# We need to make sure the dependencies are installed
8+
# because we run jest from node_modules
109
yarn
11-
yarn test "$@"
10+
cd test-plugin
11+
make -s out/index.js
12+
# We must keep jest in a sub-directory. See ../../test/package.json for more
13+
# information. We must also run it from the root otherwise coverage will not
14+
# include our source files.
15+
cd "$OLDPWD"
16+
./test/node_modules/.bin/jest "$@"
1217
}
1318

1419
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"],

0 commit comments

Comments
 (0)