Skip to content

Commit 686adf0

Browse files
committed
ci: fail on "rejected promise not handled"
Problem: Unhandled "rejected promises" are silently ignored when running tests in CI. Solution: Enable CI failure for `run_and_report`.
1 parent 902b7dc commit 686adf0

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

buildspec/linuxTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ phases:
3636
# Ensure that "foo | run_and_report" fails correctly.
3737
set -o pipefail
3838
. buildspec/shared/common.sh
39-
2>&1 xvfb-run npm test --silent | run_and_report \
39+
2>&1 xvfb-run npm test --silent | run_and_report 2 \
4040
'rejected promise not handled' \
4141
'This typically indicates a bug. Read https://developer.mozilla.org/docs/Web/JavaScript/Guide/Using_promises#error_handling'
4242
}

buildspec/shared/common.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1+
#!/bin/env bash
2+
13
# Common functions used by other CI scripts.
24
# "Include" this file by sourcing (not executing) it:
35
# . buildspec/shared/common.sh
46

7+
# Ignore these patterns when deciding if the build should fail.
8+
# - "waiting for browser": from `ssoAccessTokenProvider.test.ts`, unclear how to fix it.
9+
# - "Webview is disposed": only happens on vscode "minimum" (1.68.0)
10+
# - "HTTPError: Response code …": caused by github rate-limiting.
11+
_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404'
12+
if [ "$VSCODE_TEST_VERSION" = 'minimum' ]; then
13+
_ignore_pat="$_ignore_pat"'\|Webview is disposed'
14+
fi
15+
516
# Expects stdin + two args:
6-
# 1: grep pattern
7-
# 2: message shown at end of report, if pattern was found in stdin.
17+
# 1: error code to return on failure
18+
# 2: grep pattern
19+
# 3: message shown at end of report, if pattern was found in stdin.
820
# Usage:
9-
# echo foo | run_and_report '.*' 'You must fix this. See https://example.com'
21+
# echo foo | run_and_report 1 '.*' 'You must fix this. See https://example.com'
1022
run_and_report() {
1123
set -o pipefail
12-
local pat="${1}"
13-
local msg="${2}"
24+
local errcode="${1}"
25+
local pat="${2}"
26+
local msg="${3}"
1427
local r=0
1528
mkfifo testout
1629
(cat testout &)
1730
# Capture messages that we may want to fail (or report) later.
1831
tee testout \
1932
| { grep > testout-err --line-buffered -E "$pat" || true; }
33+
2034
echo ''
21-
if grep "$pat" testout-err | sort; then
22-
printf '\nERROR: Found %s "%s" in test output (see above).\n%s\n\n' \
23-
"$(grep "${pat}" testout-err | wc -l | tr -d ' ')" \
35+
36+
if grep -v "${_ignore_pat}" testout-err | grep "$pat" | sort; then
37+
printf '\nERROR: Test output matched this pattern %s times:\n "%s"\n%s\n\n' \
38+
"$(grep -c "${pat}" testout-err)" \
2439
"$pat" \
2540
" ${msg}"
26-
# TODO: fail the CI job
27-
# r=1
28-
r=0
41+
r=${errcode}
42+
else
43+
printf '\nOK: Not found in test output: "%s"\n' "$pat"
2944
fi
45+
3046
rm -f testout testout-err
3147
return "$r"
3248
}

buildspec/shared/linux-pre_build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ if [ "$TOOLKITS_CODEARTIFACT_DOMAIN" ] && [ "$TOOLKITS_CODEARTIFACT_REPO" ] && [
2222
fi
2323

2424
# TODO: move this to the "install" phase?
25-
npm 2>&1 ci | run_and_report 'npm WARN deprecated' 'Deprecated dependencies must be updated.'
25+
# TODO: fail in CI
26+
npm 2>&1 ci | run_and_report 0 'npm WARN deprecated' 'Deprecated dependencies must be updated.'

0 commit comments

Comments
 (0)