Skip to content

Commit 665af9f

Browse files
committed
test(exception-propagation): add test for the uncaught Promise rejections handler when not in the pmjs environment
1 parent 06d8288 commit 665af9f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#! /bin/bash
2+
#
3+
# @file uncaught-rejection-handler.bash
4+
# For testing if the actual JS error gets printed out for uncaught Promise rejections,
5+
# instead of printing out a Python `Future exception was never retrieved` error message when not in pmjs
6+
#
7+
# @author Tom Tang ([email protected])
8+
# @date June 2024
9+
10+
set -u
11+
set -o pipefail
12+
13+
panic()
14+
{
15+
echo "FAIL: $*" >&2
16+
exit 2
17+
}
18+
19+
cd `dirname "$0"` || panic "could not change to test directory"
20+
21+
code='
22+
import asyncio
23+
import pythonmonkey as pm
24+
25+
async def pythonmonkey_main():
26+
pm.eval("""void Promise.reject(new TypeError("abc"));""")
27+
await pm.wait()
28+
29+
asyncio.run(pythonmonkey_main())
30+
'
31+
32+
OUTPUT=$(python -c "$code" \
33+
< /dev/null 2>&1
34+
)
35+
36+
echo "$OUTPUT" \
37+
| tr -d '\r' \
38+
| (grep -c 'Future exception was never retrieved' || true) \
39+
| while read qty
40+
do
41+
echo "$OUTPUT"
42+
[ "$qty" != "0" ] && panic "There shouldn't be a 'Future exception was never retrieved' error massage"
43+
break
44+
done || exit $?
45+
46+
echo "$OUTPUT" \
47+
| tr -d '\r' \
48+
| grep -c 'Uncaught TypeError: abc' \
49+
| while read qty
50+
do
51+
[ "$qty" != "1" ] && panic "It should print out 'Uncaught TypeError' directly"
52+
break
53+
done || exit $?

0 commit comments

Comments
 (0)