Skip to content

Commit cc68bb6

Browse files
Migrate to Jest 17, and add support for task ID (#38)
1 parent 70b79fd commit cc68bb6

34 files changed

+2034
-3992
lines changed

Diff for: .eslintignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ node_modules/*
55
production_node_modules/*
66
test/fixtures/*
77
tmp/*
8-
jest.config.js
8+
9+
/babel.config.js
10+
/jest.config.js
11+
/jest.runner.config.js
12+
13+
/.eslintrc
14+
/.eslintrc.*
15+
/test/.eslintrc
16+
/test/.eslintrc.*

Diff for: .eslintrc

-77
This file was deleted.

Diff for: .eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
tsconfigRootDir: __dirname,
5+
project: ['./tsconfig.json'],
6+
},
7+
extends: '@exercism/eslint-config-tooling',
8+
}

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.0.0
4+
5+
- Rewritten for jest 17
6+
37
## 2.3.0
48

59
- Update dependencies

Diff for: Dockerfile

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM node:erbium-buster-slim as runner
2-
# Node.js v12 LTS (Erbium)
3-
# Debian Buster (v10.4)
1+
FROM node:16-bullseye-slim as runner
2+
# Node.js 16 (curently LTS)
3+
# Debian bullseye
44

55
# fetch latest security updates
66
RUN set -ex; \
@@ -22,6 +22,10 @@ COPY . .
2222
RUN set -ex; \
2323
yarn install; \
2424
yarn build; \
25+
# install all the development modules (used for building)
26+
rm -rf node_modules; \
27+
# install only the node_modules we need for production
28+
yarn install --production; \
2529
# clean our yarn cache
2630
yarn cache clean;
2731

Diff for: babel.config.js

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1+
// This file is only used by jest.runner.config.js, when running the
2+
// test-runner. The tool itself uses typescript's compilation instead.
13
module.exports = {
2-
presets: [
3-
[
4-
'@babel/env',
5-
{
6-
targets: {
7-
node: 'current',
8-
},
9-
useBuiltIns: false,
10-
},
11-
],
12-
'@babel/preset-typescript',
13-
],
14-
plugins: [
15-
'@babel/proposal-class-properties',
16-
'@babel/proposal-object-rest-spread',
17-
'@babel/plugin-syntax-bigint',
18-
],
4+
presets: ['@exercism/babel-preset-typescript'],
5+
plugins: [],
196
}

Diff for: bin/run.sh

+32-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Synopsis:
4-
# Automatically tests exercism's JS track solutions against corresponding test files.
4+
# Automatically tests exercism's TS track solutions against corresponding test files.
55
# Takes two-three arguments and makes sure all the tests are run
66

77
# Arguments:
@@ -78,6 +78,7 @@ set -euo pipefail
7878
ROOT="$(realpath $(dirname "$0")/..)"
7979
REPORTER="$ROOT/dist/reporter.js"
8080
SETUP="$ROOT/dist/jest/setup.js"
81+
CONFIG="$ROOT/jest.runner.config.js"
8182

8283
if test -f "$REPORTER"; then
8384
echo "Using reporter : $REPORTER"
@@ -101,16 +102,31 @@ fi
101102
echo ""
102103

103104
configuration_file="${INPUT}.meta/config.json"
105+
local_configuration_file="${INPUT}.exercism/config.json"
106+
104107

105108
# Prepare the test file(s)
109+
mkdir -p "${OUTPUT}"
110+
111+
if [[ "${INPUT}" -ef "${OUTPUT}" ]]; then
112+
echo "${INPUT} matches ${OUTPUT}. Not copying anything."
113+
else
114+
echo "Copying ${INPUT} to ${OUTPUT}."
115+
cp -r "${INPUT}" "${OUTPUT}"
116+
fi
106117

107118
if test -f $configuration_file; then
108119
echo "Using ${configuration_file} as base configuration"
109-
cat $configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${INPUT}
120+
cat $configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${OUTPUT}
110121
else
111-
test_file="${SLUG}.test.ts"
112-
echo "No configuration given. Falling back to ${test_file}"
113-
"$ROOT/bin/prepare.sh" ${INPUT} ${test_file}
122+
if test -f $local_configuration_file; then
123+
echo "Using ${local_configuration_file} as base configuration"
124+
cat $local_configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${OUTPUT}
125+
else
126+
test_file="${SLUG}.test.ts"
127+
echo "No configuration given. Falling back to ${test_file}"
128+
"$ROOT/bin/prepare.sh" ${OUTPUT} ${test_file}
129+
fi;
114130
fi;
115131

116132
# Put together the path to the test results file
@@ -163,17 +179,19 @@ else
163179
fi
164180

165181
# Run tests
166-
( "$ROOT/node_modules/.bin/jest" "${INPUT}*" \
167-
--outputFile="${result_file}" \
168-
--reporters "${REPORTER}" \
182+
"$ROOT/node_modules/.bin/jest" "${OUTPUT}*" \
183+
--bail 1 \
184+
--ci \
185+
--colors \
186+
--config ${CONFIG} \
169187
--noStackTrace \
170-
--verbose=false \
171-
--roots "${INPUT}" \
188+
--outputFile="${result_file}" \
172189
--passWithNoTests \
173-
--ci \
174-
--runInBand \
175-
--bail 1 \
176-
--setupFilesAfterEnv ${SETUP} )
190+
--reporters "${REPORTER}" \
191+
--roots "${OUTPUT}" \
192+
--setupFilesAfterEnv ${SETUP} \
193+
--verbose false \
194+
--testLocationInResults
177195

178196
# Convert exit(1) (jest worked, but there are failing tests) to exit(0)
179197
test_exit=$?

Diff for: jest.config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
12
module.exports = {
2-
verbose: true,
3-
modulePathIgnorePatterns: ['package.json'],
4-
transform: {
5-
'^.+\\.[t|j]sx?$': 'babel-jest',
6-
},
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
75
}

Diff for: jest.runner.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
verbose: true,
3+
modulePathIgnorePatterns: ['package.json'],
4+
transform: {
5+
'^.+\\.[t|j]sx?$': 'babel-jest',
6+
},
7+
reporters: [],
8+
}

Diff for: package.json

+20-28
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,33 @@
2424
"watch": "yarn build -w",
2525
"prepare": "yarn build",
2626
"prepublishOnly": "yarn test:bare && yarn lint",
27-
"lint": "yarn eslint . --ext ts,js,tsx,jsx,mjs -c .eslintrc",
27+
"lint": "yarn eslint src --ext ts,js,tsx,jsx,mjs -c .eslintrc.js && yarn eslint test --ext ts,js,tsx,jsx,mjs -c test/.eslintrc.js",
2828
"test": "yarn build && yarn test:bare",
2929
"test:bare": "jest --roots test --testPathIgnorePatterns=\"fixtures/\""
3030
},
3131
"dependencies": {
32-
"@types/jest": "^26.0.24",
33-
"@types/node": "^14.18.0",
34-
"@babel/cli": "^7.16.0",
35-
"@babel/core": "^7.16.5",
36-
"@babel/node": "^7.16.5",
37-
"@babel/plugin-proposal-class-properties": "^7.16.5",
38-
"@babel/plugin-proposal-object-rest-spread": "^7.16.5",
39-
"@babel/plugin-syntax-bigint": "^7.8.3",
40-
"@babel/preset-env": "^7.16.5",
41-
"@babel/preset-typescript": "^7.16.5",
42-
"@exercism/static-analysis": "^0.11.0",
43-
"@typescript-eslint/typescript-estree": "^5.7.0",
44-
"@typescript-eslint/visitor-keys": "^5.7.0",
45-
"babel-jest": "^26.6.3",
46-
"chalk": "^4.1.2",
47-
"jest": "^26.6.3",
48-
"jest-util": "^26.6.2",
49-
"slash": "^3.0.0",
50-
"string-length": "^4.0.2",
51-
"typescript": "^4.5.4"
32+
"@exercism/babel-preset-typescript": "^0.1.0",
33+
"@exercism/static-analysis": "^0.12.0",
34+
"@typescript-eslint/typescript-estree": "^5.11.0",
35+
"@typescript-eslint/visitor-keys": "^5.11.0",
36+
"babel-jest": "^27.5.1",
37+
"chalk": "^5.0.0",
38+
"jest": "^27.5.1",
39+
"typescript": "^4.5.5"
5240
},
5341
"devDependencies": {
54-
"@typescript-eslint/eslint-plugin": "^5.7.0",
55-
"@typescript-eslint/parser": "^5.7.0",
56-
"babel-eslint": "^10.1.0",
57-
"eslint": "^8.4.1",
42+
"@exercism/eslint-config-tooling": "^0.4.0",
43+
"@tsconfig/node16": "^1.0.2",
44+
"@types/jest": "^27.4.0",
45+
"@types/node": "^16.11.24",
46+
"@typescript-eslint/eslint-plugin": "^5.11.0",
47+
"@typescript-eslint/parser": "^5.11.0",
48+
"eslint": "^8.9.0",
5849
"eslint-config-prettier": "^8.3.0",
59-
"eslint-plugin-import": "^2.25.3",
60-
"eslint-plugin-jest": "^25.3.0",
50+
"eslint-plugin-import": "^2.25.4",
51+
"eslint-plugin-jest": "^26.1.0",
6152
"prettier": "^2.5.1",
62-
"rimraf": "^3.0.2"
53+
"rimraf": "^3.0.2",
54+
"ts-jest": "^27.1.3"
6355
}
6456
}

Diff for: src/getResultHeader.ts

-75
This file was deleted.

0 commit comments

Comments
 (0)