Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Jest 17, and add support for task ID #38

Merged
merged 3 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.0.0

- Rewritten for jest 17

## 2.3.0

- Update dependencies
Expand Down
10 changes: 7 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 All @@ -22,6 +22,10 @@ COPY . .
RUN set -ex; \
yarn install; \
yarn build; \
# install all the development modules (used for building)
rm -rf node_modules; \
# install only the node_modules we need for production
yarn install --production; \
# clean our yarn cache
yarn cache clean;

Expand Down
21 changes: 4 additions & 17 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +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,
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/plugin-syntax-bigint',
],
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
46 changes: 32 additions & 14 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

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

# Arguments:
Expand Down Expand Up @@ -78,6 +78,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 All @@ -101,16 +102,31 @@ fi
echo ""

configuration_file="${INPUT}.meta/config.json"
local_configuration_file="${INPUT}.exercism/config.json"


# Prepare the test file(s)
mkdir -p "${OUTPUT}"

if [[ "${INPUT}" -ef "${OUTPUT}" ]]; then
echo "${INPUT} matches ${OUTPUT}. Not copying anything."
else
echo "Copying ${INPUT} to ${OUTPUT}."
cp -r "${INPUT}" "${OUTPUT}"
fi

if test -f $configuration_file; then
echo "Using ${configuration_file} as base configuration"
cat $configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${INPUT}
cat $configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${OUTPUT}
else
test_file="${SLUG}.test.ts"
echo "No configuration given. Falling back to ${test_file}"
"$ROOT/bin/prepare.sh" ${INPUT} ${test_file}
if test -f $local_configuration_file; then
echo "Using ${local_configuration_file} as base configuration"
cat $local_configuration_file | jq -c '.files.test[]' | xargs -L 1 "$ROOT/bin/prepare.sh" ${OUTPUT}
else
test_file="${SLUG}.test.ts"
echo "No configuration given. Falling back to ${test_file}"
"$ROOT/bin/prepare.sh" ${OUTPUT} ${test_file}
fi;
fi;

# Put together the path to the test results file
Expand Down Expand Up @@ -163,17 +179,19 @@ else
fi

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

# 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: [],
}
48 changes: 20 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,33 @@
"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": {
"@types/jest": "^26.0.24",
"@types/node": "^14.18.0",
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.5",
"@babel/node": "^7.16.5",
"@babel/plugin-proposal-class-properties": "^7.16.5",
"@babel/plugin-proposal-object-rest-spread": "^7.16.5",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.16.5",
"@babel/preset-typescript": "^7.16.5",
"@exercism/static-analysis": "^0.11.0",
"@typescript-eslint/typescript-estree": "^5.7.0",
"@typescript-eslint/visitor-keys": "^5.7.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",
"typescript": "^4.5.4"
"@exercism/babel-preset-typescript": "^0.1.0",
"@exercism/static-analysis": "^0.12.0",
"@typescript-eslint/typescript-estree": "^5.11.0",
"@typescript-eslint/visitor-keys": "^5.11.0",
"babel-jest": "^27.5.1",
"chalk": "^5.0.0",
"jest": "^27.5.1",
"typescript": "^4.5.5"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"babel-eslint": "^10.1.0",
"eslint": "^8.4.1",
"@exercism/eslint-config-tooling": "^0.4.0",
"@tsconfig/node16": "^1.0.2",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.24",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.0",
"prettier": "^2.5.1",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3"
}
}
75 changes: 0 additions & 75 deletions src/getResultHeader.ts

This file was deleted.

Loading