Skip to content

Commit

Permalink
Rewrite the test runner to work with Jest 27 (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte authored Feb 6, 2022
1 parent 4c35235 commit 94cf624
Show file tree
Hide file tree
Showing 45 changed files with 2,344 additions and 5,082 deletions.
10 changes: 9 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ node_modules/*
production_node_modules/*
test/fixtures/*
tmp/*
jest.config.js

/babel.config.js
/jest.config.js
/jest.runner.config.js

/.eslintrc
/.eslintrc.*
/test/.eslintrc
/test/.eslintrc.*
77 changes: 0 additions & 77 deletions .eslintrc

This file was deleted.

8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
extends: '@exercism/eslint-config-tooling',
}
6 changes: 3 additions & 3 deletions .github/workflows/ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Use Node.js LTS (14.x)
- name: Use Node.js LTS (16.x)
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 16.x

- name: Install project dependencies
run: yarn install --frozen-lockfile --ignore-scripts
Expand All @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [16.x]

steps:
- uses: actions/checkout@v2
Expand Down
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
6 changes: 3 additions & 3 deletions .github/workflows/pr.ci.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout PR
uses: actions/checkout@v2

- name: Use Node.js LTS (14.x)
- name: Use Node.js LTS (16.x)
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 16.x

- name: Install project dependencies
run: yarn install --frozen-lockfile --ignore-scripts
Expand All @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [16.x]

steps:
- name: Checkout PR
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'
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.0

- Rewrite for Jest 27
- Sanitize jest reported syntax errors

## 2.5.1

- Fix skipped tests showing up as failed despite passed complete status.
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:erbium-buster-slim as runner
# Node.js v12 LTS (Erbium)
# Debian Buster (v10.4)
FROM node:16-bullseye-slim as runner
# Node.js 16 (curently LTS)
# Debian bullseye

# fetch latest security updates
RUN set -ex; \
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

The Docker image for automatically run tests on JavaScript solutions submitted to [exercism][web-exercism].

> At this moment, the input path _must_ be relative to the `package.json` of this respository.
> At this moment, the input path _must_ be relative to the `package.json` of this repository.
> `jest` doesn't like running outside of its tree.
> This might change in the future.
## Installation

Clone this repository and then run:

```bash
```shell
yarn install
```

You'll need at least Node LTS for this to work.

```
```shell
yarn build
```

Expand Down Expand Up @@ -48,11 +48,15 @@ For example:
```shell
$ ./bin/run.sh two-fer ./test/fixtures/two-fer/pass

PASS test/fixtures/two-fer/pass/two-fer.spec.js
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 2.817s
Using reporter : **/dist/reporter.js
Using test-root: **/test/fixtures/two-fer/pass/
Using base-root: **/
Using setup-env: **/dist/jest/setup.js

test/fixtures/two-fer/pass/ matches test/fixtures/two-fer/pass/. Not copying anything.
Using test/fixtures/two-fer/pass/.meta/config.json as base configuration
Enabling tests in test/fixtures/two-fer/pass/two-fer.spec.js
Determining test suites to run...
Find the output at:
test/fixtures/two-fer/pass/results.json
```
Expand All @@ -76,11 +80,10 @@ Exercism remote UUID: a7d1b71693fb4298a3a99bd352dd4d74
Downloaded to
C:\Users\Derk-Jan\Exercism\javascript\clock
PASS tmp/clock/a7d1b71693fb4298a3a99bd352dd4d74/clock/clock.spec.js
Test Suites: 1 passed, 1 total
Tests: 52 passed, 52 total
Snapshots: 0 total
Time: 2.987s
...
Determining test suites to run...
Find the output at:
./tmp/clock/a7d1b71693fb4298a3a99bd352dd4d74/clock/results.json
```
Expand Down
15 changes: 4 additions & 11 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
// This file is only used by jest.runner.config.js, when running the
// test-runner. The tool itself uses typescript's compilation instead.
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},
],
],
presets: ['@exercism/babel-preset-javascript'],
plugins: [],
}
19 changes: 12 additions & 7 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set -euo pipefail
ROOT="$(realpath $(dirname "$0")/..)"
REPORTER="$ROOT/dist/reporter.js"
SETUP="$ROOT/dist/jest/setup.js"
CONFIG="$ROOT/jest.runner.config.js"

if test -f "$REPORTER"; then
echo "Using reporter : $REPORTER"
Expand Down Expand Up @@ -132,17 +133,21 @@ set +e

# Run tests
"$ROOT/node_modules/.bin/jest" "${OUTPUT}*" \
--bail 1 \
--ci \
--colors \
--config ${CONFIG} \
--noStackTrace \
--outputFile="${result_file}" \
--passWithNoTests \
--reporters "${REPORTER}" \
--noStackTrace \
--verbose=false \
--roots "${OUTPUT}" \
--passWithNoTests \
--ci \
--runInBand \
--bail 1 \
--setupFilesAfterEnv ${SETUP}
--setupFilesAfterEnv ${SETUP} \
--verbose false \
--testLocationInResults


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

Expand Down
8 changes: 3 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
verbose: true,
modulePathIgnorePatterns: ['package.json'],
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
},
preset: 'ts-jest',
testEnvironment: 'node',
}
8 changes: 8 additions & 0 deletions jest.runner.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
verbose: true,
modulePathIgnorePatterns: ['package.json'],
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
},
reporters: [],
}
51 changes: 25 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@exercism/javascript-test-runner",
"description": "Automated Test runner for exercism solutions in Javascript.",
"author": "Derk-Jan Karrenbeld <derk-jan+github@karrenbeld.info>",
"version": "2.5.1",
"version": "3.0.0",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
Expand All @@ -24,38 +24,37 @@
"watch": "yarn build -w",
"prepare": "yarn build",
"prepublishOnly": "yarn test:bare && yarn lint",
"lint": "yarn eslint . --ext ts,js,tsx,jsx,mjs -c .eslintrc",
"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",
"test": "yarn build && yarn test:bare",
"test:bare": "jest --roots test --testPathIgnorePatterns=\"fixtures/\""
},
"dependencies": {
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@babel/node": "^7.15.4",
"@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.2",
"jest": "^26.6.3",
"jest-util": "^26.6.2",
"slash": "^3.0.0",
"string-length": "^4.0.2"
"@babel/core": "^7.17.0",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@exercism/babel-preset-javascript": "^0.1.2",
"@exercism/static-analysis": "^0.11.0",
"@typescript-eslint/typescript-estree": "^5.10.2",
"@typescript-eslint/visitor-keys": "^5.10.2",
"babel-jest": "^27.5.0",
"chalk": "^5.0.0",
"jest": "^27.5.0"
},
"devDependencies": {
"@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.32.0",
"@exercism/eslint-config-tooling": "^0.4.0",
"@tsconfig/node16": "^1.0.2",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.22",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.0",
"prettier": "^2.3.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.0.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"typescript": "^4.4.2"
"ts-jest": "^27.1.3",
"typescript": "^4.5.5"
}
}
1 change: 0 additions & 1 deletion src/declarations.d.ts

This file was deleted.

Loading

0 comments on commit 94cf624

Please sign in to comment.