Skip to content

Initial files #1

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

Merged
merged 10 commits into from
Oct 23, 2019
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
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:lts-alpine as builder

# Install SSL ca certificates
RUN apk update && apk add ca-certificates
RUN apk upgrade

# Create appuser
RUN adduser -D -g '' appuser

WORKDIR /javascript-test-runner
COPY . .

# Only install the node_modules we need
RUN yarn install --production --modules-folder './production_node_modules'

# Build a minimal and secured container
FROM node:lts-alpine
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /javascript-test-runner/package.json /opt/test-runner/package.json
COPY --from=builder /javascript-test-runner/bin /opt/test-runner/bin
COPY --from=builder /javascript-test-runner/production_node_modules /opt/test-runner/node_modules
USER appuser
WORKDIR /opt/test-runner

COPY ./run.sh ./bin/

ENTRYPOINT [ "sh", "/opt/test-runner/bin/run.sh" ]
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Exercism

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# JavaScript Test Runner
# Exercism JavaScript Test Runner

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

## Running the Tests

To run a solution's tests, do the following:
1. Open termnial in project's root
2. Run `./run.sh <exercise-slug> <path-to-solution-folder>`

## Running the Tests in Docker container

*This script is provided for testing purposes*

To run a solution's test in the Docker container, do the following:
1. Open terminal in project's root
2. Run `./run-in-docker.sh <exercise-slug> <relative-path-to-solution-folder>`

## Maintaining

The `package.json` needs to be in-sync with the [`javascript` track `package.json`][git-javascript].

### Known issues

* The output format of the tests still does not conform to the [exercism automated tests][git-automated-tests] standard.

[web-exercism]: https://exercism.io
[git-automated-tests]: https://github.com/exercism/automated-tests
[git-javascript]: https://github.com/exercism/javascript
38 changes: 38 additions & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

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

# Arguments:
# $1: exercise slug
# $2: path to solution folder (without trailing slash)
# $3: path to output directory (without trailing slash)

# Output:
# Writes the tests output to the output directory

# Example:
# ./run.sh two-fer path/to/two-fer/solution/folder path/to/output-directory

# Put together the path to the test file
test_file="$2/$1.spec.js"

# Put together the path to the test results file
result_file="$2/results.xml"
package_json_source = "package.json"
package_json="$2/package.json"

# Change xtest to test so all tests are run
sed -i 's/xtest/test/g' $test_file
sed -i 's/xit/it/g' $test_file

# Symlink the node_modules we have, then install missing packages
ln -sf production_node_modules $2/node_modules
yarn install --cwd $2

# Afterwards, copy the Package.json
cp $package_json_source $package_json
sed -i "s/{result_file}/${result_file}/g" $package_json

yarn test:cli --cwd $2
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@exercism/javascript-test-runner",
"description": "Automated Test runner for exercism solutions in Javascript.",
"author": "Katrina Owen",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/exercism/javascript-test-runner"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/node": "^7.6.3",
"@babel/preset-env": "^7.6.3",
"@types/jest": "^24.0.19",
"@types/node": "^12.11.5",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"eslint-plugin-import": "^2.18.2",
"jest": "^24.9.0",
"jest-junit": "^9.0.0"
},
"jest": {
"modulePathIgnorePatterns": [
"package.json"
]
},
"scripts": {
"test": "jest --no-cache ./*",
"watch": "jest --no-cache --watch ./*",
"lint": "eslint .",
"lint-test": "eslint . && jest --no-cache ./* ",
"test:cli": "jest --no-cache ./* --outputFile={result_file} --reporters=jest-junit"
},
"license": "MIT",
"dependencies": {}
}
33 changes: 33 additions & 0 deletions run-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Synopsis:
# Test runner for run.sh in a docker container
# Takes the same arguments as run.sh (EXCEPT THAT SOLUTION AND OUTPUT PATH ARE RELATIVE)
# Builds the Dockerfile
# Runs the docker image passing along the initial arguments

# Arguments:
# $1: exercise slug
# $2: **RELATIVE** path to solution folder (without trailing slash)
# $3: **RELATIVE** path to output directory (without trailing slash)

# Output:
# Writes the tests output to the output directory

# Example:
# ./run-in-docker.sh two-fer ./relative/path/to/two-fer/solution/folder ./relative/path/to/output-directory

# If arguments not provided, print usage and exit
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "usage: ./run-in-docker.sh two-fer ./relative/path/to/two-fer/solution/folder ./relative/path/to/output-directory"
fi

# build docker image
docker build -t javascript-test-runner .

# run image passing the arguments
# run image passing the arguments
docker run \
--mount type=bind,src=$PWD/$2,dst=/solution \
--mount type=bind,src=$PWD/$3,dst=/output \
javascript-test-runner $1 /solution /output