File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 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 $?
You can’t perform that action at this time.
0 commit comments