|
1 | | -#!/bin/bash -eu |
| 1 | +#!/bin/bash -e |
2 | 2 | set -o pipefail |
3 | 3 |
|
| 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. |
4 | 6 | cp index.html public/ |
5 | 7 | 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. |
6 | 11 | 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 -- . |
16 | 22 | 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