kibana/.buildkite/scripts/steps/test/jest_parallel.sh
Gerard Soldevila 6a7c904f92
SKA: Relocate "platform" packages that remain on /packages (#208704)
## Summary

The `/packages` folder at the root of the Kibana repository used to
contain a lot of packages.
In the context of SKA, they have been gradually moved to various
locations:
* `src/platform/packages`
* `x-pack/platform/packages`
* `src/core/packages`

Currently, only `devOnly: true` packages are left in this folder. This
comprises libraries for CLI scripts as well as testing utilities.

With this PR, we are moving ~half of these packages under
`src/platform/packages/(private|shared)/`.
In particular, we are moving those packages that are being used from
platform and/or solutions.

Since they are `"devOnly": true`, this means they are ONLY used from
tests, cypress tests, storybook configs, ./scripts/ folders inside some
modules, or other non-prod-time logic. Nonetheless, they are effectively
referenced from platform and/or solutions code, hence I decided they
should be placed under `platform` folders.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-02-24 11:03:30 +00:00

117 lines
3 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
source "$(dirname "$0")/../../common/util.sh"
export JOB=${BUILDKITE_PARALLEL_JOB:-0}
# a jest failure will result in the script returning an exit code of 10
exitCode=0
results=()
configs=""
failedConfigs=""
if [[ "$1" == 'jest.config.js' ]]; then
# we used to run jest tests in parallel but started to see a lot of flakiness in libraries like react-dom/test-utils:
# https://github.com/elastic/kibana/issues/141477
# parallelism="-w2"
parallelism="--runInBand"
TEST_TYPE="unit"
else
# run integration tests in-band
parallelism="--runInBand"
TEST_TYPE="integration"
fi
export TEST_TYPE
# Added section for tracking and retrying failed configs
FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${TEST_TYPE}${JOB}"
if [[ ! "$configs" && "${BUILDKITE_RETRY_COUNT:-0}" == "1" ]]; then
configs=$(buildkite-agent meta-data get "$FAILED_CONFIGS_KEY" --default '')
if [[ "$configs" ]]; then
echo "--- Retrying only failed configs"
echo "$configs"
fi
fi
if [ "$configs" == "" ]; then
echo "--- downloading jest test run order"
download_artifact jest_run_order.json .
configs=$(jq -r 'getpath([env.TEST_TYPE]) | .groups[env.JOB | tonumber].names | .[]' jest_run_order.json)
fi
if [ "$configs" == "" ]; then
echo "unable to determine configs to run"
exit 1
fi
echo "+++ ⚠️ WARNING ⚠️"
echo "
console.log(), console.warn(), and console.error() output in jest tests causes a massive amount
of noise on CI without any percevable benefit, so they have been disabled. If you want to log
output in your test temporarily, you can modify 'src/platform/packages/shared/kbn-test/src/jest/setup/disable_console_logs.js'
"
while read -r config; do
echo "--- $ node scripts/jest --config $config"
# --trace-warnings to debug
# Node.js process-warning detected:
# Warning: Closing file descriptor 24 on garbage collection
cmd="NODE_OPTIONS=\"--max-old-space-size=12288 --trace-warnings"
if [ "${KBN_ENABLE_FIPS:-}" == "true" ]; then
cmd=$cmd" --enable-fips --openssl-config=$HOME/nodejs.cnf"
fi
cmd=$cmd"\" node ./scripts/jest --config=\"$config\" $parallelism --coverage=false --passWithNoTests"
echo "actual full command is:"
echo "$cmd"
echo ""
start=$(date +%s)
# prevent non-zero exit code from breaking the loop
set +e;
eval "$cmd"
lastCode=$?
set -e;
timeSec=$(($(date +%s)-start))
if [[ $timeSec -gt 60 ]]; then
min=$((timeSec/60))
sec=$((timeSec-(min*60)))
duration="${min}m ${sec}s"
else
duration="${timeSec}s"
fi
results+=("- $config
duration: ${duration}
result: ${lastCode}")
if [ $lastCode -ne 0 ]; then
exitCode=10
echo "Jest exited with code $lastCode"
echo "^^^ +++"
if [[ "$failedConfigs" ]]; then
failedConfigs="${failedConfigs}"$'\n'"$config"
else
failedConfigs="$config"
fi
fi
done <<< "$configs"
if [[ "$failedConfigs" ]]; then
buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "$failedConfigs"
fi
echo "--- Jest configs complete"
printf "%s\n" "${results[@]}"
echo ""
exit $exitCode