Skip to content

Commit 43537b8

Browse files
committed
Make test runner more resilient
- Run tests in batches on CircleCI. - Allow a low number of warnings.
1 parent e6d657c commit 43537b8

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

karma.conf.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ module.exports = (config) => {
5757
browsers: ['ChromeHeadless'],
5858
reporters: ['spec'],
5959
singleRun: true,
60+
client: {
61+
mocha: { grep: process.env.TEST_PATTERN || '.' }
62+
},
6063
customLaunchers: {
6164
ChromeDebugging: {
6265
base: 'Chrome',

test/run.sh

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
1-
#!/bin/bash -eu
1+
#!/bin/bash -e
22
set -o pipefail
33

4+
# Normally, index.html is housed at the root of the repository for Vite, but
5+
# here we move it to public/, where Vue CLI expects it.
46
cp index.html public/
57
output=$(mktemp)
8+
# -f ensures that $output is removed even if public/index.html has already been
9+
# removed by another process. Even if removing public/index.html fails, we want
10+
# to ensure that $output is removed.
611
trap 'rm -f -- public/index.html "$output"' EXIT
7-
NODE_ENV=test karma start | tee "$output"
8-
# Search for: warnings from console.warn(), including Vue warnings; Sass
9-
# warnings; and warnings from Karma.
10-
if grep -F -e 'WARN LOG:' -e 'ERROR LOG:' -e 'Module Warning' -e 'WARN [web-server]:' -C5 "$output"; then
11-
# Reset the text format in case the search results contained formatted text.
12-
tput sgr0
13-
echo
14-
echo 'All tests passed, but there were warnings: see above.'
15-
exit 1
12+
13+
# We've been running into issues trying to run all tests at once in CircleCI.
14+
# Instead, we'll run tests in batches.
15+
if [[ "$CIRCLECI" = 'true' ]]; then
16+
# There are many tests of components whose name starts with "Form" (F) or
17+
# "Submission" (S). There are also many tests of functions whose name starts
18+
# with "create" (c) or "use" (u).
19+
set -- F S '[cu]' '[^FScu]'
20+
else
21+
set -- .
1622
fi
23+
for pattern in "$@"; do
24+
pattern="^$pattern"
25+
echo
26+
echo "Running tests that match the pattern $pattern"
27+
NODE_ENV=test TEST_PATTERN="$pattern" karma start | tee "$output"
28+
29+
# Search for: warnings from console.warn(), including Vue warnings; Sass
30+
# warnings; and warnings from Karma.
31+
set -- -F -e 'WARN LOG:' -e 'ERROR LOG:' -e 'Module Warning' -e 'WARN [web-server]:' "$output"
32+
warnings=$(grep -c "$@")
33+
if (( $warnings > 4 )); then
34+
grep -C5 "$@"
35+
# Reset the text format in case the search results contained formatted text.
36+
tput sgr0
37+
echo
38+
echo "All tests passed, but there were $warnings warnings: see above."
39+
exit 1
40+
elif (( $warnings > 0 )); then
41+
echo "There were $warnings warnings, which is within the accepted threshold."
42+
fi
43+
44+
# Give the machine a little time to reclaim resources.
45+
[[ "$CIRCLECI" = 'true' ]] && sleep 3
46+
done

0 commit comments

Comments
 (0)