@@ -11,20 +11,26 @@ results=()
1111configs=" "
1212failedConfigs=" "
1313
14+ # Parallel execution tuning (can be overridden via env)
15+ # JEST_MAX_PARALLEL: number of concurrent Jest config processes
16+ # JEST_MAX_OLD_SPACE_MB: per-process max old space size (MB)
17+ # NOTE: JEST_MAX_PARALLEL default now depends on TEST_TYPE (unit=3, integration=1).
18+ # It can still be overridden by exporting JEST_MAX_PARALLEL.
19+ JEST_MAX_PARALLEL=" ${JEST_MAX_PARALLEL:- 3} "
20+ JEST_MAX_OLD_SPACE_MB=" ${JEST_MAX_OLD_SPACE_MB:- 8192} "
21+
1422if [[ " $1 " == ' jest.config.js' ]]; then
15- # we used to run jest tests in parallel but started to see a lot of flakiness in libraries like react-dom/test-utils:
16- # https://github.com/elastic/kibana/issues/141477
17- # parallelism="-w2"
18- parallelism=" --runInBand"
23+ # unit tests
1924 TEST_TYPE=" unit"
25+ JEST_MAX_PARALLEL=3 # unit tests run in parallel by default. When adjusting Buildkite resources, dont forget to update this value.
2026else
21- # run integration tests in-band
22- parallelism=" --runInBand"
2327 TEST_TYPE=" integration"
28+ JEST_MAX_PARALLEL=1 # integration tests should not run in parallel by default.
2429fi
2530
2631export TEST_TYPE
2732
33+
2834# Added section for tracking and retrying failed configs
2935FAILED_CONFIGS_KEY=" ${BUILDKITE_STEP_ID}${TEST_TYPE}${JOB} "
3036
5056echo " +++ ⚠️ WARNING ⚠️"
5157echo "
5258 console.log(), console.warn(), and console.error() output in jest tests causes a massive amount
53- of noise on CI without any percevable benefit, so they have been disabled. If you want to log
59+ of noise on CI without any perceivable benefit, so they have been disabled. If you want to log
5460 output in your test temporarily, you can modify 'src/platform/packages/shared/kbn-test/src/jest/setup/disable_console_logs.js'
5561"
5662
57- while read -r config; do
58- echo " --- $ node scripts/jest --config $config "
59-
60- # --trace-warnings to debug
61- # Node.js process-warning detected:
62- # Warning: Closing file descriptor 24 on garbage collection
63- cmd=" NODE_OPTIONS=\" --max-old-space-size=12288 --trace-warnings --no-experimental-require-module"
64-
65- if [ " ${KBN_ENABLE_FIPS:- } " == " true" ]; then
66- cmd=$cmd " --enable-fips --openssl-config=$HOME /nodejs.cnf"
67- fi
68-
69- cmd=$cmd " \" NODE_ENV=test node ./scripts/jest --config=\" $config \" $parallelism --coverage=false --passWithNoTests"
63+ # Execute all configs through the combined jest_all runner.
64+ # The new runner will handle iterating through configs and reporting.
7065
71- echo " actual full command is:"
72- echo " $cmd "
73- echo " "
66+ # Flatten configs (newline separated) into comma-separated list for flag usage.
67+ CONFIGS_CSV=$( echo " $configs " | tr ' \n' ' ,' | sed ' s/,$//' )
7468
75- start=$( date +%s)
69+ echo " --- Running combined jest_all for configs ($TEST_TYPE )"
70+ echo " $configs "
71+ echo " JEST_MAX_PARALLEL is set to: $JEST_MAX_PARALLEL "
7672
77- # prevent non-zero exit code from breaking the loop
78- set +e;
79- eval " $cmd "
80- lastCode=$?
81- set -e;
82-
83- timeSec=$(( $(date +% s)- start))
84- if [[ $timeSec -gt 60 ]]; then
85- min=$(( timeSec/ 60 ))
86- sec=$(( timeSec- (min* 60 )) )
87- duration=" ${min} m ${sec} s"
88- else
89- duration=" ${timeSec} s"
90- fi
73+ node_opts=" --max-old-space-size=${JEST_MAX_OLD_SPACE_MB} --trace-warnings --no-experimental-require-module"
74+ if [ " ${KBN_ENABLE_FIPS:- } " == " true" ]; then
75+ node_opts=" $node_opts --enable-fips --openssl-config=$HOME /nodejs.cnf"
76+ fi
9177
92- results+=(" - $config
93- duration: ${duration}
94- result: ${lastCode} " )
78+ full_command=" NODE_OPTIONS=\" $node_opts \" node ./scripts/jest_all --configs=\" $CONFIGS_CSV \" --coverage=false --passWithNoTests --maxParallel=\" $JEST_MAX_PARALLEL \" "
9579
96- if [ $lastCode -ne 0 ]; then
97- exitCode=10
98- echo " Jest exited with code $lastCode "
99- echo " ^^^ +++"
80+ echo " Actual full command is:"
81+ echo " $full_command "
82+ echo " "
10083
101- if [[ " $failedConfigs " ]]; then
102- failedConfigs=" ${failedConfigs} " $' \n ' " $config "
103- else
104- failedConfigs=" $config "
105- fi
106- fi
107- done <<< " $configs"
84+ set +e
85+ eval " $full_command "
86+ code=$?
87+ set -e
10888
109- if [[ " $failedConfigs " ] ]; then
110- buildkite-agent meta-data set " $FAILED_CONFIGS_KEY " " $failedConfigs "
89+ if [ $code -ne 0 ]; then
90+ exitCode=10
11191fi
11292
113- echo " --- Jest configs complete"
114- printf " %s\n" " ${results[@]} "
115- echo " "
93+ echo " --- Jest configs complete (combined)"
11694
11795# Scout reporter
11896source .buildkite/scripts/steps/test/scout_upload_report_events.sh
11997
120- exit $exitCode
98+ exit $exitCode
0 commit comments