Skip to content

Commit 6e41c0c

Browse files
Tweak smoke tests (#62)
1 parent 53b1f2b commit 6e41c0c

File tree

11 files changed

+276
-1
lines changed

11 files changed

+276
-1
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ dev.Dockerfile
99
.gitignore
1010
.gitattributes
1111
.dockerignore
12+
/bin/
13+
!/bin/run.sh
14+
!/bin/prepare.sh
15+
test/

.github/workflows/ci.js.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install project dependencies
2222
run: yarn install --frozen-lockfile
2323

24-
- name: Run exercism/javascript-test-runner ci precheck (lint code)
24+
- name: Run exercism/typescript-test-runner ci precheck (lint code)
2525
run: bin/lint.sh
2626

2727
ci:
@@ -43,3 +43,21 @@ jobs:
4343

4444
- name: Build the test-runner (using Node ${{ matrix.node-version }})
4545
run: bin/test.sh
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1
49+
with:
50+
install: true
51+
52+
- name: Build Docker image and store in cache
53+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825
54+
with:
55+
context: .
56+
push: false
57+
load: true
58+
tags: exercism/typescript-test-runner
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
61+
62+
- name: Run Tests in Docker
63+
run: bin/run-tests-in-docker.sh

.github/workflows/pr.ci.js.yml

+18
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ jobs:
4545

4646
- name: Build the test-runner (using Node ${{ matrix.node-version }})
4747
run: bin/test.sh
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1
51+
with:
52+
install: true
53+
54+
- name: Build Docker image and store in cache
55+
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825
56+
with:
57+
context: .
58+
push: false
59+
load: true
60+
tags: exercism/typescript-test-runner
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max
63+
64+
- name: Run Tests in Docker
65+
run: bin/run-tests-in-docker.sh

bin/run-tests-in-docker.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env sh
2+
3+
# Synopsis:
4+
# Test the test runner Docker image by running it against a predefined set of
5+
# solutions with an expected output.
6+
# The test runner Docker image is built automatically.
7+
8+
# Output:
9+
# Outputs the diff of the expected test results against the actual test results
10+
# generated by the test runner Docker image.
11+
12+
# Example:
13+
# ./bin/run-tests-in-docker.sh
14+
15+
# Stop executing when a command returns a non-zero return code
16+
set -e
17+
18+
# Build the Docker image
19+
docker build --rm -t exercism/typescript-test-runner .
20+
21+
# Run the Docker image using the settings mimicking the production environment
22+
docker run \
23+
--rm \
24+
--network none \
25+
--read-only \
26+
--mount type=bind,src="${PWD}/test/fixtures",dst=/opt/test-runner/test/fixtures \
27+
--mount type=tmpfs,dst=/tmp \
28+
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \
29+
--workdir /opt/test-runner \
30+
--entrypoint /opt/test-runner/bin/run-tests.sh \
31+
exercism/typescript-test-runner

bin/run-tests.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# Synopsis:
4+
# Test the test runner by running it against a predefined set of solutions
5+
# with an expected output.
6+
7+
# Output:
8+
# Outputs the diff of the expected test results against the actual test results
9+
# generated by the test runner.
10+
11+
# Example:
12+
# ./bin/run-tests.sh
13+
14+
exit_code=0
15+
16+
# We need to copy the fixtures to a temp directory as the user
17+
# running within the Docker container does not have permissions
18+
# to run the sed command on the fixtures directory
19+
fixtures_dir="test/fixtures"
20+
tmp_fixtures_dir="/tmp/test/fixtures"
21+
rm -rf "${tmp_fixtures_dir}"
22+
mkdir -p "${tmp_fixtures_dir}"
23+
cp -R ${fixtures_dir}/* "${tmp_fixtures_dir}"
24+
25+
# Iterate over all test directories
26+
for test_file in $(find "${tmp_fixtures_dir}" -name '*.test.ts'); do
27+
slug=$(echo "${test_file:${#tmp_fixtures_dir}+1}" | cut -d / -f 1)
28+
test_dir=$(dirname "${test_file}")
29+
test_dir_name=$(basename "${test_dir}")
30+
test_dir_path=$(realpath "${test_dir}")
31+
results_file_path="${test_dir_path}/results.json"
32+
expected_results_file_path="${test_dir_path}/expected_results.json"
33+
34+
# Make sure there is no existing node_modules directory
35+
rm -rf "${test_dir_path}/node_modules"
36+
37+
bin/run.sh "${slug}" "${test_dir_path}" "${test_dir_path}"
38+
39+
echo "${slug}/${test_dir_name}: comparing results.json to expected_results.json"
40+
diff "${results_file_path}" "${expected_results_file_path}"
41+
42+
if [ $? -ne 0 ]; then
43+
exit_code=1
44+
fi
45+
done
46+
47+
exit ${exit_code}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"status": "pass",
3+
"tests": [
4+
{
5+
"name": "Triplet > triplets whose sum is 12",
6+
"status": "pass",
7+
"message": "",
8+
"output": null,
9+
"test_code": "expect(tripletsWithSum(12)).toEqual([[3, 4, 5]])"
10+
},
11+
{
12+
"name": "Triplet > triplets whose sum is 108",
13+
"status": "pass",
14+
"message": "",
15+
"output": null,
16+
"test_code": "expect(tripletsWithSum(108)).toEqual([[27, 36, 45]])"
17+
},
18+
{
19+
"name": "Triplet > triplets whose sum is 1000",
20+
"status": "pass",
21+
"message": "",
22+
"output": null,
23+
"test_code": "expect(tripletsWithSum(1000)).toEqual([[200, 375, 425]])"
24+
},
25+
{
26+
"name": "Triplet > no matching triplets for 1001",
27+
"status": "pass",
28+
"message": "",
29+
"output": null,
30+
"test_code": "expect(tripletsWithSum(1001)).toEqual([])"
31+
},
32+
{
33+
"name": "Triplet > returns all matching triplets",
34+
"status": "pass",
35+
"message": "",
36+
"output": null,
37+
"test_code": "expect(tripletsWithSum(90)).toEqual([\n [9, 40, 41],\n [15, 36, 39],\n ])"
38+
},
39+
{
40+
"name": "Triplet > several matching triplets",
41+
"status": "pass",
42+
"message": "",
43+
"output": null,
44+
"test_code": "expect(tripletsWithSum(840)).toEqual([\n [40, 399, 401],\n [56, 390, 394],\n [105, 360, 375],\n [120, 350, 370],\n [140, 336, 364],\n [168, 315, 357],\n [210, 280, 350],\n [240, 252, 348],\n ])"
45+
},
46+
{
47+
"name": "Triplet > returns triplets with no factor smaller than minimum factor",
48+
"status": "pass",
49+
"message": "",
50+
"output": null,
51+
"test_code": "expect(tripletsWithSum(90, { minFactor: 10 })).toEqual([[15, 36, 39]])"
52+
},
53+
{
54+
"name": "Triplet > returns triplets with no factor larger than maximum factor",
55+
"status": "pass",
56+
"message": "",
57+
"output": null,
58+
"test_code": "expect(tripletsWithSum(840, { maxFactor: 349 })).toEqual([[240, 252, 348]])"
59+
},
60+
{
61+
"name": "Triplet > returns triplets with factors in range",
62+
"status": "pass",
63+
"message": "",
64+
"output": null,
65+
"test_code": "expect(tripletsWithSum(840, { maxFactor: 352, minFactor: 150 })).toEqual([\n [210, 280, 350],\n [240, 252, 348],\n ])"
66+
}
67+
],
68+
"version": 3
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"status": "error",
3+
"message": "SyntaxError: <solution>/two-fer.test.ts: Unexpected token (2:0)\n\n \u001b[0m \u001b[90m 1 |\u001b[39m describe(\u001b[32m'twoFer()'\u001b[39m\u001b[33m,\u001b[39m t(\u001b[32m'another name given'\u001b[39m\u001b[33m,\u001b[39m () \u001b[33m=>\u001b[39m {\u001b[0m\n \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 2 |\u001b[39m\u001b[0m\n \u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n",
4+
"tests": [],
5+
"version": 3
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "version": 1, "status": "error", "message": "The submitted code didn't compile. We have collected the errors encountered during compilation. At this moment the error messages are not very read-friendly, but it's a start. We are working on a more helpful output.\n-------------------------------\ntwo-fer.ts(1,14): error TS1389: 'const' is not allowed as a variable declaration name.\ntwo-fer.ts(1,20): error TS1134: Variable declaration expected.\ntwo-fer.ts(1,29): error TS1109: Expression expected.\ntwo-fer.ts(2,1): error TS1005: ')' expected." }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"status": "fail",
3+
"tests": [
4+
{
5+
"name": "TwoFer > no name given",
6+
"status": "fail",
7+
"message": "TypeError: (0 , _twoFer.twoFer) is not a function",
8+
"output": null,
9+
"test_code": "const expected = 'One for you, one for me.'\nexpect(twoFer()).toEqual(expected)"
10+
},
11+
{
12+
"name": "TwoFer > a name given",
13+
"status": "fail",
14+
"message": "TypeError: (0 , _twoFer.twoFer) is not a function",
15+
"output": null,
16+
"test_code": "const expected = 'One for Alice, one for me.'\nexpect(twoFer('Alice')).toEqual(expected)"
17+
},
18+
{
19+
"name": "TwoFer > another name given",
20+
"status": "fail",
21+
"message": "TypeError: (0 , _twoFer.twoFer) is not a function",
22+
"output": null,
23+
"test_code": "const expected = 'One for Bob, one for me.'\nexpect(twoFer('Bob')).toEqual(expected)"
24+
}
25+
],
26+
"version": 3
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"status": "fail",
3+
"tests": [
4+
{
5+
"name": "TwoFer > no name given",
6+
"status": "pass",
7+
"message": "",
8+
"output": "[log] ",
9+
"test_code": "const expected = 'One for you, one for me.'\nexpect(twoFer('')).toEqual(expected)"
10+
},
11+
{
12+
"name": "TwoFer > a name given",
13+
"status": "fail",
14+
"message": "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoEqual\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // deep equality\u001b[22m\n\nExpected: \u001b[32m\"One for \u001b[7mAlice\u001b[27m, one for me.\"\u001b[39m\nReceived: \u001b[31m\"One for \u001b[7myou\u001b[27m, one for me.\"\u001b[39m",
15+
"output": "[log] Some global log\n[log] Alice",
16+
"test_code": "const expected = 'One for Alice, one for me.'\nexpect(twoFer('Alice')).toEqual(expected)"
17+
},
18+
{
19+
"name": "TwoFer > another name given",
20+
"status": "fail",
21+
"message": "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoEqual\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // deep equality\u001b[22m\n\nExpected: \u001b[32m\"One for \u001b[7mBob\u001b[27m, one for me.\"\u001b[39m\nReceived: \u001b[31m\"One for \u001b[7myou\u001b[27m, one for me.\"\u001b[39m",
22+
"output": "[log] Bob",
23+
"test_code": "const expected = 'One for Bob, one for me.'\nexpect(twoFer('Bob')).toEqual(expected)"
24+
}
25+
],
26+
"version": 3
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"status": "pass",
3+
"tests": [
4+
{
5+
"name": "TwoFer > no name given",
6+
"status": "pass",
7+
"message": "",
8+
"output": null,
9+
"test_code": "const expected = 'One for you, one for me.'\nexpect(twoFer()).toEqual(expected)"
10+
},
11+
{
12+
"name": "TwoFer > a name given",
13+
"status": "pass",
14+
"message": "",
15+
"output": null,
16+
"test_code": "const expected = 'One for Alice, one for me.'\nexpect(twoFer('Alice')).toEqual(expected)"
17+
},
18+
{
19+
"name": "TwoFer > another name given",
20+
"status": "pass",
21+
"message": "",
22+
"output": null,
23+
"test_code": "const expected = 'One for Bob, one for me.'\nexpect(twoFer('Bob')).toEqual(expected)"
24+
}
25+
],
26+
"version": 3
27+
}

0 commit comments

Comments
 (0)