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

Use config.json when available #36

Merged
merged 2 commits into from
Apr 2, 2021
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.3.0

- Enable `.meta/config.json`
- Add test that _requires_ `.meta/config.json` files to be set

## 2.2.1

- Upgrade `@exercism/static-analysis`
Expand Down
25 changes: 25 additions & 0 deletions bin/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# prepare <directory> <file>

test_file="$1$2"
test_file=${test_file//$'\r'}


if test -f "$test_file"; then
# Change xtest to test so all tests are run
if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OS X
# BSD sed -i takes an extra parameter to specify the backup file extension
sed -i 'tmp' 's/xtest(/test(/g' "${test_file}"
sed -i 'tmp' 's/xit(/it(/g' "${test_file}"
sed -i 'tmp' 's/xdescribe(/describe(/g' "${test_file}"
else
echo "Enabling tests in $test_file"

sed -i 's/xtest(/test(/g' "${test_file}"
sed -i 's/xit(/it(/g' "${test_file}"
sed -i 's/xdescribe(/describe(/g' "${test_file}"
fi
else
echo "Can't find $test_file"
fi;
28 changes: 12 additions & 16 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,22 @@ fi

echo ""

# Put together the path to the test file
test_file="${INPUT}${SLUG}.spec.js"
configuration_file="${INPUT}.meta/config.json"

# Prepare the test file(s)

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}
else
test_file="${SLUG}.spec.js"
echo "No configuration give. Falling back to ${test_file}"
"$ROOT/bin/prepare.sh" ${INPUT} ${test_file}
fi;

# Put together the path to the test results file
result_file="${OUTPUT}results.json"

if test -f "$test_file"; then
# Change xtest to test so all tests are run
if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OS X
# BSD sed -i takes an extra parameter to specify the backup file extension
sed -i 'tmp' 's/xtest(/test(/g' "${test_file}"
sed -i 'tmp' 's/xit(/it(/g' "${test_file}"
sed -i 'tmp' 's/xdescribe(/describe(/g' "${test_file}"
else
sed -i 's/xtest(/test(/g' "${test_file}"
sed -i 's/xit(/it(/g' "${test_file}"
sed -i 's/xdescribe(/describe(/g' "${test_file}"
fi
fi

mkdir -p "${OUTPUT}"

# Disable auto exit
Expand Down
2 changes: 1 addition & 1 deletion 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.2.1",
"version": "2.3.0",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/poetry-club-door-policy/pass/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"blurb": "Learn about strings using poems to get into the poetry club.",
"authors": ["SleeplessByte"],
"contributors": ["hayashi-ay"],
"files": {
"solution": ["door-policy.js"],
"test": ["door-policy.spec.js"],
"exemplar": [".meta/exemplar.js"]
},
"forked_from": []
}
74 changes: 74 additions & 0 deletions test/fixtures/poetry-club-door-policy/pass/.meta/exemplar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check
//
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion on the web
// and supported IDEs when implementing this exercise. You don't need to
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
// exercise, and can completely ignore this comment block and directive.
//
// 👋🏽 Hi again!
//
// A quick reminder about exercise stubs:
//
// 💡 You're allowed to completely clear any stub before you get started. Often
// we recommend using the stub, because they are already set-up correctly to
// work with the tests, which you can find in ./door-policy.spec.js.
//
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
//
// Good luck with that door policy!

/**
* Respond with the correct character, given the blurb, if this were said at
* the front door.
*
* @param {string} blurb
* @returns {string}
*/
export function frontDoorResponse(blurb) {
return blurb[0];
}

/**
* Respond with the correct character, given the blurb, if this were said at
* the back door.
*
* @param {string} blurb
* @returns {string}
*/
export function backDoorResponse(blurb) {
const trimmed = blurb.trim();
return trimmed[trimmed.length - 1];
}

/**
* Give the password for the front-door, given the responses.
*
* @param {string} responses the responses
* @returns {string} the password
*/
export function frontDoorPassword(responses) {
return capitalize(responses);
}

/**
* Give the password for the back-door, given the responses.
*
* @param {string} responses the responses
* @returns {string} the password
*/
export function backDoorPassword(responses) {
return `${capitalize(responses)}, please`;
}

/**
* Capitalizes a word, meaning only the first character is a capital, and the
* remaining letters are lower case.
*
* @param {string} word
* @returns {string}
*/
function capitalize(word) {
return word[0].toUpperCase() + word.slice(1).toLowerCase();
}
74 changes: 74 additions & 0 deletions test/fixtures/poetry-club-door-policy/pass/door-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check
//
// ☝🏽 The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion on the web
// and supported IDEs when implementing this exercise. You don't need to
// understand types, JSDoc, or TypeScript in order to complete this JavaScript
// exercise, and can completely ignore this comment block and directive.
//
// 👋🏽 Hi again!
//
// A quick reminder about exercise stubs:
//
// 💡 You're allowed to completely clear any stub before you get started. Often
// we recommend using the stub, because they are already set-up correctly to
// work with the tests, which you can find in ./door-policy.spec.js.
//
// 💡 You don't need to write JSDoc comment blocks yourself; it is not expected
// in idiomatic JavaScript, but some companies and style-guides do enforce them.
//
// Good luck with that door policy!

/**
* Respond with the correct character, given the blurb, if this were said at
* the front door.
*
* @param {string} blurb
* @returns {string}
*/
export function frontDoorResponse(blurb) {
return blurb[0];
}

/**
* Respond with the correct character, given the blurb, if this were said at
* the back door.
*
* @param {string} blurb
* @returns {string}
*/
export function backDoorResponse(blurb) {
const trimmed = blurb.trim();
return trimmed[trimmed.length - 1];
}

/**
* Give the password for the front-door, given the responses.
*
* @param {string} responses the responses
* @returns {string} the password
*/
export function frontDoorPassword(responses) {
return capitalize(responses);
}

/**
* Give the password for the back-door, given the responses.
*
* @param {string} responses the responses
* @returns {string} the password
*/
export function backDoorPassword(responses) {
return `${capitalize(responses)}, please`;
}

/**
* Capitalizes a word, meaning only the first character is a capital, and the
* remaining letters are lower case.
*
* @param {string} word
* @returns {string}
*/
function capitalize(word) {
return word[0].toUpperCase() + word.slice(1).toLowerCase();
}
Loading