-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unused results.json files * Add scripts to run and run tests in Docker * Update CI to run smoke tests * Update dockerignore * Update expected values
- Loading branch information
1 parent
62caf46
commit 07b38c0
Showing
25 changed files
with
263 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ node_modules | |
.gitattributes | ||
.dockerignore | ||
Dockerfile | ||
bin/* | ||
!bin/run.sh | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Run the representer on a solution using the representer Docker image. | ||
# The representer Docker image is built automatically. | ||
|
||
# Arguments: | ||
# $1: exercise slug | ||
# $2: absolute path to solution folder | ||
# $3: absolute path to output directory | ||
|
||
# Output: | ||
# Writes the test results to a results.json file in the passed-in output directory. | ||
# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/representers/interface.md | ||
|
||
# Example: | ||
# ./bin/run-in-docker.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/ | ||
|
||
# If any required arguments is missing, print the usage and exit | ||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | ||
echo "usage: ./bin/run-in-docker.sh exercise-slug /absolute/path/to/solution/folder/ /absolute/path/to/output/directory/" | ||
exit 1 | ||
fi | ||
|
||
slug="$1" | ||
input_dir="${2%/}" | ||
output_dir="${3%/}" | ||
|
||
# Create the output directory if it doesn't exist | ||
mkdir -p "${output_dir}" | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/javascript-representer . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,source="${input_dir}",destination=/solution \ | ||
--mount type=bind,source="${output_dir}",destination=/output \ | ||
--mount type=tmpfs,destination=/tmp \ | ||
exercism/javascript-representer "${slug}" /solution /output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer Docker image by running it against a predefined set of | ||
# solutions with an expected output. | ||
# The representer Docker image is built automatically. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests-in-docker.sh | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/javascript-representer . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,source="${PWD}/test",destination=/opt/representer/test \ | ||
--mount type=tmpfs,destination=/tmp \ | ||
--volume "${PWD}/bin/run-tests.sh:/opt/representer/bin/run-tests.sh" \ | ||
--workdir /opt/representer \ | ||
--entrypoint /opt/representer/bin/run-tests.sh \ | ||
exercism/javascript-representer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer by running it against a predefined set of solutions | ||
# with an expected output. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests.sh | ||
|
||
exit_code=0 | ||
|
||
# We need to copy the fixtures to a temp directory as the user | ||
# running within the Docker container does not have permissions | ||
# to run the sed command on the fixtures directory | ||
fixtures_dir="test/fixtures" | ||
tmp_fixtures_dir="/tmp/test/fixtures" | ||
rm -rf "${tmp_fixtures_dir}" | ||
mkdir -p "${tmp_fixtures_dir}" | ||
cp -R ${fixtures_dir}/* "${tmp_fixtures_dir}" | ||
|
||
# Iterate over all test directories | ||
for test_file in $(find "${tmp_fixtures_dir}" -name '*.spec.js'); do | ||
slug=$(echo "${test_file:${#tmp_fixtures_dir}+1}" | cut -d / -f 1) | ||
test_dir=$(dirname "${test_file}") | ||
test_dir_name=$(basename "${test_dir}") | ||
test_dir_path=$(realpath "${test_dir}") | ||
|
||
bin/run.sh "${slug}" "${test_dir_path}" "${test_dir_path}" | ||
|
||
for file in representation.txt mapping.json; do | ||
expected_file="expected_${file}" | ||
echo "${test_dir_name}: comparing ${file} to ${expected_file}" | ||
|
||
if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then | ||
exit_code=1 | ||
fi | ||
done | ||
done | ||
|
||
exit ${exit_code} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"IDENTIFIER_0": "MINUTES_PER_HOUR", | ||
"IDENTIFIER_1": "HOURS_ON_THE_CLOCK", | ||
"IDENTIFIER_2": "MINUTES_PER_CLOCK", | ||
"IDENTIFIER_3": "normalize", | ||
"IDENTIFIER_4": "minutes", | ||
"IDENTIFIER_5": "console", | ||
"IDENTIFIER_6": "log", | ||
"IDENTIFIER_8": "number", | ||
"IDENTIFIER_9": "padStart", | ||
"IDENTIFIER_11": "hours", | ||
"IDENTIFIER_12": "plus", | ||
"IDENTIFIER_13": "minus", | ||
"IDENTIFIER_14": "equals", | ||
"IDENTIFIER_15": "other" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const IDENTIFIER_0 = 60; | ||
const IDENTIFIER_1 = 24; | ||
const IDENTIFIER_2 = IDENTIFIER_0 * IDENTIFIER_1; | ||
function IDENTIFIER_3(IDENTIFIER_4) { | ||
while (IDENTIFIER_4 < 0) { | ||
IDENTIFIER_5.IDENTIFIER_6("minutes < 0", IDENTIFIER_4); | ||
IDENTIFIER_4 += IDENTIFIER_2; | ||
} | ||
return IDENTIFIER_4 % IDENTIFIER_2; | ||
} | ||
export const clockPad = IDENTIFIER_8 => { | ||
return String(IDENTIFIER_8).IDENTIFIER_9(2, '0'); | ||
}; | ||
export class Clock { | ||
constructor(IDENTIFIER_11, IDENTIFIER_4 = 0) { | ||
this.IDENTIFIER_4 = IDENTIFIER_3(IDENTIFIER_11 * IDENTIFIER_0 + IDENTIFIER_4); | ||
} | ||
toString() { | ||
const IDENTIFIER_11 = Math.floor(this.IDENTIFIER_4 / IDENTIFIER_0); | ||
const IDENTIFIER_4 = this.IDENTIFIER_4 % IDENTIFIER_0; | ||
return `${clockPad(IDENTIFIER_11)}:${clockPad(IDENTIFIER_4)}`; | ||
} | ||
IDENTIFIER_12(IDENTIFIER_4) { | ||
return new Clock(0, this.IDENTIFIER_4 + IDENTIFIER_4); | ||
} | ||
IDENTIFIER_13(IDENTIFIER_4) { | ||
return this.IDENTIFIER_12(-IDENTIFIER_4); | ||
} | ||
valueOf() { | ||
return this.IDENTIFIER_4; | ||
} | ||
IDENTIFIER_14(IDENTIFIER_15) { | ||
return +IDENTIFIER_15 === +this; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/general/normalize-whitespace/expected_mapping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"IDENTIFIER_1": "name" | ||
} |
1 change: 1 addition & 0 deletions
1
test/fixtures/general/normalize-whitespace/expected_representation.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const twoFer = (IDENTIFIER_1 = 'you') => `One for ${IDENTIFIER_1}, one for me.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const twoFer = (name = 'you') => `One for ${name}, one for me.` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"IDENTIFIER_1": "name" | ||
} |
1 change: 1 addition & 0 deletions
1
test/fixtures/general/remove-comments/expected_representation.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const twoFer = (IDENTIFIER_1 = 'you') => `One for ${IDENTIFIER_1}, one for me.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const twoFer = (name = 'you') => `One for ${name}, one for me.` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { twoFer } from './two-fer'; | ||
|
||
describe('twoFer()', () => { | ||
test('no name given', () => { | ||
expect(twoFer()).toEqual('One for you, one for me.'); | ||
}); | ||
|
||
test('a name given', () => { | ||
const name = 'Alice'; | ||
expect(twoFer(name)).toEqual('One for Alice, one for me.'); | ||
}); | ||
|
||
test('another name given', () => { | ||
const name = 'Bob'; | ||
expect(twoFer(name)).toEqual('One for Bob, one for me.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"IDENTIFIER_1": "n", | ||
"IDENTIFIER_2": "console", | ||
"IDENTIFIER_3": "debug", | ||
"IDENTIFIER_4": "log" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const twoFer = IDENTIFIER_1 => { | ||
IDENTIFIER_2.IDENTIFIER_3(IDENTIFIER_1); | ||
return `One for you, one for me.`; | ||
}; | ||
IDENTIFIER_2.IDENTIFIER_3("Hello there debug message"); | ||
IDENTIFIER_2.IDENTIFIER_4("Ok there log message"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"IDENTIFIER_1": "name" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const twoFer = (IDENTIFIER_1 = 'you') => `One for ${IDENTIFIER_1}, one for me.`; |
This file was deleted.
Oops, something went wrong.