Skip to content

Commit 943c69d

Browse files
Run tsc on tests (#21)
* Run tsc on tests * Format using package.json
1 parent 3b31ab3 commit 943c69d

File tree

22 files changed

+1552
-1023
lines changed

22 files changed

+1552
-1023
lines changed

.appends/.github/labels.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
# https://github.com/exercism/org-wide-files/blob/main/global-files/.github/labels.yml. #
44
# ----------------------------------------------------------------------------------------- #
55

6-
- name: "bug"
6+
- name: 'bug'
77
description: "Something isn't working"
8-
color: "d73a4a"
8+
color: 'd73a4a'
99

10-
- name: "dependencies"
11-
description: "Pull requests that update a dependency file"
12-
color: "0366d6"
10+
- name: 'dependencies'
11+
description: 'Pull requests that update a dependency file'
12+
color: '0366d6'
1313

14-
- name: "documentation"
15-
description: "Improvements or additions to documentation"
16-
color: "0075ca"
14+
- name: 'documentation'
15+
description: 'Improvements or additions to documentation'
16+
color: '0075ca'
1717

18-
- name: "duplicate"
19-
description: "This issue or pull request already exists"
20-
color: "cfd3d7"
18+
- name: 'duplicate'
19+
description: 'This issue or pull request already exists'
20+
color: 'cfd3d7'
2121

22-
- name: "enhancement"
23-
description: "New feature or request"
24-
color: "a2eeef"
22+
- name: 'enhancement'
23+
description: 'New feature or request'
24+
color: 'a2eeef'
2525

26-
- name: "good first issue"
27-
description: "Good for newcomers"
28-
color: "7057ff"
26+
- name: 'good first issue'
27+
description: 'Good for newcomers'
28+
color: '7057ff'
2929

30-
- name: "help wanted"
31-
description: "Extra attention is needed"
32-
color: "008672"
30+
- name: 'help wanted'
31+
description: 'Extra attention is needed'
32+
color: '008672'
3333

34-
- name: "invalid"
34+
- name: 'invalid'
3535
description: "This doesn't seem right"
36-
color: "e4e669"
36+
color: 'e4e669'
3737

38-
- name: "question"
39-
description: "Further information is requested"
40-
color: "d876e3"
38+
- name: 'question'
39+
description: 'Further information is requested'
40+
color: 'd876e3'
4141

42-
- name: "wontfix"
43-
description: "This will not be worked on"
44-
color: "ffffff"
42+
- name: 'wontfix'
43+
description: 'This will not be worked on'
44+
color: 'ffffff'

.github/workflows/format-code.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
6363
- name: 'Format code'
6464
run: ./bin/format.sh
65-
env:
66-
EXERCISM_PRETTIER_VERSION: '2.2.1'
6765

6866
- name: 'Commit formatted code'
6967
run: |

.github/workflows/verify-code-formatting.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ jobs:
1414

1515
- name: 'Verify formatting of all files'
1616
run: ./bin/check-formatting.sh
17-
env:
18-
EXERCISM_PRETTIER_VERSION: '2.2.1'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.0.0
4+
5+
- Implement `tsc` compilation
6+
37
## 1.0.2
48

59
- Fix output's conditional assignment

bin/check-formatting.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
#!/bin/bash
22

3-
set -euo pipefail
3+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
7+
8+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what yarn list reports:"
14+
echo "$(yarn list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
25+
fi
426

527
npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/format.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail
3+
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4+
echo "Pulling prettier version from package.json"
5+
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
6+
fi
47

58
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
6-
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
7-
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
8-
exit 1
9+
echo "---------------------------------------------------"
10+
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
11+
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
12+
echo "---------------------------------------------------"
13+
echo "This is what yarn list reports:"
14+
echo "$(yarn list prettier)"
15+
echo ""
16+
echo "This is the version that can be extracted:"
17+
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
18+
echo ""
19+
echo "These files are found in the repo root:"
20+
echo "$(ls -p | grep -v /)"
21+
echo "---------------------------------------------------"
22+
exit 1
23+
else
24+
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
925
fi
1026

1127
npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/run.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ else
4141
# access to:
4242
#
4343
# - published: https://exercism.io/tracks/typescript/exercises/clock/solutions/c3b826d95cb54441a8f354d7663e9e16
44-
# - own: https://exercism.io/my/solutions/c3b826d95cb54441a8f354d7663e9e16
45-
# - mentoring: https://exercism.io/mentor/solutions/c3b826d95cb54441a8f354d7663e9e16
4644
# - private: https://exercism.io/solutions/c3b826d95cb54441a8f354d7663e9e16
4745
#
4846
uuid=$(basename $1)
@@ -123,8 +121,31 @@ mkdir -p "${OUTPUT}"
123121
# Disable auto exit
124122
set +e
125123

124+
# Run tsc
125+
tsc_result="$( cd "${INPUT}" && "$ROOT/node_modules/.bin/tsc" --noEmit 2>&1 | sed 's/"/\\"/g' )"
126+
127+
test_exit=$?
128+
129+
if [ $test_exit -eq 2 ]
130+
then
131+
# Compose the message to show to the student
132+
#
133+
# TODO: interpret the tsc_result lines and pull out the source.
134+
# We actually already have code to do this, given the cursor position
135+
#
136+
tsc_result="The submitted code didn't compile. We have collected the errors encountered during compilation. At this moment the error messages are not very read-friendly, but it's a start. We are working on a more helpful output.\n-------------------------------\n$tsc_result"
137+
echo "{ \"version\": 1, \"status\": \"error\", \"message\": \"$tsc_result\" }" > $result_file
138+
sed -Ei ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $result_file
139+
140+
# Test runner didn't fail!
141+
exit 0
142+
else
143+
echo "tsc compilation success"
144+
fi
145+
146+
126147
# Run tests
127-
"$ROOT/node_modules/.bin/jest" "${INPUT}*" \
148+
( "$ROOT/node_modules/.bin/jest" "${INPUT}*" \
128149
--outputFile="${result_file}" \
129150
--reporters "${REPORTER}" \
130151
--noStackTrace \
@@ -134,7 +155,7 @@ set +e
134155
--ci \
135156
--runInBand \
136157
--bail 1 \
137-
--setupFilesAfterEnv ${SETUP}
158+
--setupFilesAfterEnv ${SETUP} )
138159

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

package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@exercism/typescript-test-runner",
33
"description": "Automated Test runner for exercism solutions in TypeScript.",
44
"author": "Derk-Jan Karrenbeld <[email protected]>",
5-
"version": "1.0.2",
5+
"version": "2.0.0",
66
"license": "AGPL-3.0-or-later",
77
"repository": {
88
"type": "git",
@@ -29,36 +29,36 @@
2929
"test:bare": "jest --roots test --testPathIgnorePatterns=\"fixtures/\""
3030
},
3131
"dependencies": {
32-
"@babel/cli": "^7.13.14",
33-
"@babel/core": "^7.13.15",
34-
"@babel/node": "^7.13.13",
35-
"@babel/plugin-proposal-class-properties": "^7.13.0",
36-
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
32+
"@babel/cli": "^7.15.4",
33+
"@babel/core": "^7.15.5",
34+
"@babel/node": "^7.15.4",
35+
"@babel/plugin-proposal-class-properties": "^7.14.5",
36+
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
3737
"@babel/plugin-syntax-bigint": "^7.8.3",
38-
"@babel/preset-env": "^7.13.15",
39-
"@babel/preset-typescript": "^7.13.0",
40-
"@exercism/static-analysis": "^0.8.1",
41-
"@typescript-eslint/typescript-estree": "^4.21.0",
42-
"@typescript-eslint/visitor-keys": "^4.21.0",
38+
"@babel/preset-env": "^7.15.4",
39+
"@babel/preset-typescript": "^7.15.0",
40+
"@exercism/static-analysis": "^0.10.0",
41+
"@typescript-eslint/typescript-estree": "^4.30.0",
42+
"@typescript-eslint/visitor-keys": "^4.30.0",
4343
"babel-jest": "^26.6.3",
44-
"chalk": "^4.1.0",
44+
"chalk": "^4.1.2",
4545
"jest": "^26.6.3",
46-
"jest-junit": "^12.0.0",
4746
"jest-util": "^26.6.2",
4847
"slash": "^3.0.0",
4948
"string-length": "^4.0.2"
5049
},
5150
"devDependencies": {
52-
"@types/jest": "^26.0.22",
53-
"@types/node": "^14.14.37",
54-
"@typescript-eslint/eslint-plugin": "^4.21.0",
55-
"@typescript-eslint/parser": "^4.21.0",
51+
"@types/jest": "^26.0.24",
52+
"@types/node": "^14.17.14",
53+
"@typescript-eslint/eslint-plugin": "^4.30.0",
54+
"@typescript-eslint/parser": "^4.30.0",
5655
"babel-eslint": "^10.1.0",
57-
"eslint": "^7.24.0",
58-
"eslint-config-prettier": "^8.1.0",
59-
"eslint-plugin-import": "^2.22.1",
60-
"eslint-plugin-jest": "^24.3.5",
56+
"eslint": "^7.32.0",
57+
"eslint-config-prettier": "^8.3.0",
58+
"eslint-plugin-import": "^2.24.2",
59+
"eslint-plugin-jest": "^24.4.0",
60+
"prettier": "^2.3.2",
6161
"rimraf": "^3.0.2",
62-
"typescript": "^4.2.4"
62+
"typescript": "^4.4.2"
6363
}
6464
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display": "Configuration for Node LTS",
3+
"compilerOptions": {
4+
"lib": ["es2020"],
5+
"module": "commonjs",
6+
"target": "es2020",
7+
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
13+
// Because we'll be using babel
14+
// Ensure that Babel can safely transpile files in the TypeScript project
15+
"isolatedModules": true
16+
},
17+
"include": ["*", ".meta/*"],
18+
"exclude": ["node_modules"]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display": "Configuration for Node LTS",
3+
"compilerOptions": {
4+
"lib": ["es2020"],
5+
"module": "commonjs",
6+
"target": "es2020",
7+
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
13+
// Because we'll be using babel
14+
// Ensure that Babel can safely transpile files in the TypeScript project
15+
"isolatedModules": true
16+
},
17+
"include": ["*", ".meta/*"],
18+
"exclude": ["node_modules"]
19+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
// purposefully empty
2+
export {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display": "Configuration for Node LTS",
3+
"compilerOptions": {
4+
"lib": ["es2020"],
5+
"module": "commonjs",
6+
"target": "es2020",
7+
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
13+
// Because we'll be using babel
14+
// Ensure that Babel can safely transpile files in the TypeScript project
15+
"isolatedModules": true
16+
},
17+
"include": ["*", ".meta/*"],
18+
"exclude": ["node_modules"]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display": "Configuration for Node LTS",
3+
"compilerOptions": {
4+
"lib": ["es2020"],
5+
"module": "commonjs",
6+
"target": "es2020",
7+
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
13+
// Because we'll be using babel
14+
// Ensure that Babel can safely transpile files in the TypeScript project
15+
"isolatedModules": true
16+
},
17+
"include": ["*", ".meta/*"],
18+
"exclude": ["node_modules"]
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display": "Configuration for Node LTS",
3+
"compilerOptions": {
4+
"lib": ["es2020"],
5+
"module": "commonjs",
6+
"target": "es2020",
7+
8+
"strict": true,
9+
"esModuleInterop": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
13+
// Because we'll be using babel
14+
// Ensure that Babel can safely transpile files in the TypeScript project
15+
"isolatedModules": true
16+
},
17+
"include": ["*", ".meta/*"],
18+
"exclude": ["node_modules"]
19+
}

0 commit comments

Comments
 (0)