Skip to content

Commit

Permalink
Run tsc on tests (#21)
Browse files Browse the repository at this point in the history
* Run tsc on tests

* Format using package.json
  • Loading branch information
SleeplessByte authored Sep 5, 2021
1 parent 3b31ab3 commit 943c69d
Show file tree
Hide file tree
Showing 22 changed files with 1,552 additions and 1,023 deletions.
56 changes: 28 additions & 28 deletions .appends/.github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
# https://github.com/exercism/org-wide-files/blob/main/global-files/.github/labels.yml. #
# ----------------------------------------------------------------------------------------- #

- name: "bug"
- name: 'bug'
description: "Something isn't working"
color: "d73a4a"
color: 'd73a4a'

- name: "dependencies"
description: "Pull requests that update a dependency file"
color: "0366d6"
- name: 'dependencies'
description: 'Pull requests that update a dependency file'
color: '0366d6'

- name: "documentation"
description: "Improvements or additions to documentation"
color: "0075ca"
- name: 'documentation'
description: 'Improvements or additions to documentation'
color: '0075ca'

- name: "duplicate"
description: "This issue or pull request already exists"
color: "cfd3d7"
- name: 'duplicate'
description: 'This issue or pull request already exists'
color: 'cfd3d7'

- name: "enhancement"
description: "New feature or request"
color: "a2eeef"
- name: 'enhancement'
description: 'New feature or request'
color: 'a2eeef'

- name: "good first issue"
description: "Good for newcomers"
color: "7057ff"
- name: 'good first issue'
description: 'Good for newcomers'
color: '7057ff'

- name: "help wanted"
description: "Extra attention is needed"
color: "008672"
- name: 'help wanted'
description: 'Extra attention is needed'
color: '008672'

- name: "invalid"
- name: 'invalid'
description: "This doesn't seem right"
color: "e4e669"
color: 'e4e669'

- name: "question"
description: "Further information is requested"
color: "d876e3"
- name: 'question'
description: 'Further information is requested'
color: 'd876e3'

- name: "wontfix"
description: "This will not be worked on"
color: "ffffff"
- name: 'wontfix'
description: 'This will not be worked on'
color: 'ffffff'
2 changes: 0 additions & 2 deletions .github/workflows/format-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
- name: 'Format code'
run: ./bin/format.sh
env:
EXERCISM_PRETTIER_VERSION: '2.2.1'

- name: 'Commit formatted code'
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ jobs:

- name: 'Verify formatting of all files'
run: ./bin/check-formatting.sh
env:
EXERCISM_PRETTIER_VERSION: '2.2.1'
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.0

- Implement `tsc` compilation

## 1.0.2

- Fix output's conditional assignment
Expand Down
24 changes: 23 additions & 1 deletion bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!/bin/bash

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

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
24 changes: 20 additions & 4 deletions bin/format.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
#!/usr/bin/env bash

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

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
exit 1
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
29 changes: 25 additions & 4 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ else
# access to:
#
# - published: https://exercism.io/tracks/typescript/exercises/clock/solutions/c3b826d95cb54441a8f354d7663e9e16
# - own: https://exercism.io/my/solutions/c3b826d95cb54441a8f354d7663e9e16
# - mentoring: https://exercism.io/mentor/solutions/c3b826d95cb54441a8f354d7663e9e16
# - private: https://exercism.io/solutions/c3b826d95cb54441a8f354d7663e9e16
#
uuid=$(basename $1)
Expand Down Expand Up @@ -123,8 +121,31 @@ mkdir -p "${OUTPUT}"
# Disable auto exit
set +e

# Run tsc
tsc_result="$( cd "${INPUT}" && "$ROOT/node_modules/.bin/tsc" --noEmit 2>&1 | sed 's/"/\\"/g' )"

test_exit=$?

if [ $test_exit -eq 2 ]
then
# Compose the message to show to the student
#
# TODO: interpret the tsc_result lines and pull out the source.
# We actually already have code to do this, given the cursor position
#
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"
echo "{ \"version\": 1, \"status\": \"error\", \"message\": \"$tsc_result\" }" > $result_file
sed -Ei ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $result_file

# Test runner didn't fail!
exit 0
else
echo "tsc compilation success"
fi


# Run tests
"$ROOT/node_modules/.bin/jest" "${INPUT}*" \
( "$ROOT/node_modules/.bin/jest" "${INPUT}*" \
--outputFile="${result_file}" \
--reporters "${REPORTER}" \
--noStackTrace \
Expand All @@ -134,7 +155,7 @@ set +e
--ci \
--runInBand \
--bail 1 \
--setupFilesAfterEnv ${SETUP}
--setupFilesAfterEnv ${SETUP} )

# Convert exit(1) (jest worked, but there are failing tests) to exit(0)
test_exit=$?
Expand Down
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@exercism/typescript-test-runner",
"description": "Automated Test runner for exercism solutions in TypeScript.",
"author": "Derk-Jan Karrenbeld <[email protected]>",
"version": "1.0.2",
"version": "2.0.0",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
Expand All @@ -29,36 +29,36 @@
"test:bare": "jest --roots test --testPathIgnorePatterns=\"fixtures/\""
},
"dependencies": {
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.15",
"@babel/node": "^7.13.13",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@babel/node": "^7.15.4",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@exercism/static-analysis": "^0.8.1",
"@typescript-eslint/typescript-estree": "^4.21.0",
"@typescript-eslint/visitor-keys": "^4.21.0",
"@babel/preset-env": "^7.15.4",
"@babel/preset-typescript": "^7.15.0",
"@exercism/static-analysis": "^0.10.0",
"@typescript-eslint/typescript-estree": "^4.30.0",
"@typescript-eslint/visitor-keys": "^4.30.0",
"babel-jest": "^26.6.3",
"chalk": "^4.1.0",
"chalk": "^4.1.2",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"jest-util": "^26.6.2",
"slash": "^3.0.0",
"string-length": "^4.0.2"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"@types/jest": "^26.0.24",
"@types/node": "^14.17.14",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.5",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.0",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"typescript": "^4.2.4"
"typescript": "^4.4.2"
}
}
19 changes: 19 additions & 0 deletions test/fixtures/clock/pass/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}
19 changes: 19 additions & 0 deletions test/fixtures/two-fer/error/empty/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// purposefully empty
export {}
19 changes: 19 additions & 0 deletions test/fixtures/two-fer/error/malformed_tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}
19 changes: 19 additions & 0 deletions test/fixtures/two-fer/error/missing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}
19 changes: 19 additions & 0 deletions test/fixtures/two-fer/error/syntax/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display": "Configuration for Node LTS",
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 943c69d

Please sign in to comment.