From 09b7a7f0e84b7429225f9b35c40b0316ae38ecee Mon Sep 17 00:00:00 2001 From: Julian Gernun <17549662+jcger@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:14:06 +0200 Subject: [PATCH] remove not necesary test + activate logs --- .buildkite/pipelines/pull_request/base.yml | 122 +++++++++--------- .../scripts/steps/test/jest_parallel.sh | 80 ++++++------ custom-jest-environment.js | 26 ++++ .../src/jest/setup/disable_console_logs.js | 6 +- x-pack/plugins/cases/jest.config.js | 1 + 5 files changed, 131 insertions(+), 104 deletions(-) create mode 100644 custom-jest-environment.js diff --git a/.buildkite/pipelines/pull_request/base.yml b/.buildkite/pipelines/pull_request/base.yml index 2f2e0a739a304..bf2005cab8d1f 100644 --- a/.buildkite/pipelines/pull_request/base.yml +++ b/.buildkite/pipelines/pull_request/base.yml @@ -54,69 +54,69 @@ steps: timeout_in_minutes: 10 env: JEST_UNIT_SCRIPT: '.buildkite/scripts/steps/test/jest.sh' - JEST_INTEGRATION_SCRIPT: '.buildkite/scripts/steps/test/jest_integration.sh' - FTR_CONFIGS_SCRIPT: '.buildkite/scripts/steps/test/ftr_configs.sh' + # JEST_INTEGRATION_SCRIPT: '.buildkite/scripts/steps/test/jest_integration.sh' + # FTR_CONFIGS_SCRIPT: '.buildkite/scripts/steps/test/ftr_configs.sh' retry: automatic: - exit_status: '*' limit: 1 - - command: .buildkite/scripts/steps/lint.sh - label: 'Linting' - agents: - machineType: n2-standard-8 - preemptible: true - key: linting - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 - - - command: .buildkite/scripts/steps/check_types.sh - label: 'Check Types' - agents: - machineType: n2-standard-4 - preemptible: true - key: check_types - timeout_in_minutes: 70 - retry: - automatic: - - exit_status: '-1' - limit: 3 - - - command: .buildkite/scripts/steps/lint_with_types.sh - label: 'Linting (with types)' - agents: - machineType: n2-standard-16 - preemptible: true - key: linting_with_types - timeout_in_minutes: 90 - retry: - automatic: - - exit_status: '-1' - limit: 3 - - - command: .buildkite/scripts/steps/checks.sh - label: 'Checks' - key: checks - agents: - machineType: n2-standard-2 - preemptible: true - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 - - - command: .buildkite/scripts/steps/api_docs/build_api_docs.sh - label: 'Build API Docs' - agents: - machineType: n2-standard-4 - preemptible: true - key: build_api_docs - timeout_in_minutes: 90 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/lint.sh + # label: 'Linting' + # agents: + # machineType: n2-standard-8 + # preemptible: true + # key: linting + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 + # + # - command: .buildkite/scripts/steps/check_types.sh + # label: 'Check Types' + # agents: + # machineType: n2-standard-4 + # preemptible: true + # key: check_types + # timeout_in_minutes: 70 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 + # + # - command: .buildkite/scripts/steps/lint_with_types.sh + # label: 'Linting (with types)' + # agents: + # machineType: n2-standard-16 + # preemptible: true + # key: linting_with_types + # timeout_in_minutes: 90 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 + # + # - command: .buildkite/scripts/steps/checks.sh + # label: 'Checks' + # key: checks + # agents: + # machineType: n2-standard-2 + # preemptible: true + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 + # + # - command: .buildkite/scripts/steps/api_docs/build_api_docs.sh + # label: 'Build API Docs' + # agents: + # machineType: n2-standard-4 + # preemptible: true + # key: build_api_docs + # timeout_in_minutes: 90 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 diff --git a/.buildkite/scripts/steps/test/jest_parallel.sh b/.buildkite/scripts/steps/test/jest_parallel.sh index 2a7cf780f5787..b7f9703dacac0 100755 --- a/.buildkite/scripts/steps/test/jest_parallel.sh +++ b/.buildkite/scripts/steps/test/jest_parallel.sh @@ -53,51 +53,51 @@ echo " 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 'packages/kbn-test/src/jest/setup/disable_console_logs.js' " +$config="x-pack/plugins/cases/jest.config.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\" node ./scripts/jest --config=\"$config\" $parallelism --coverage=false --passWithNoTests" +echo "actual full command is:" +echo "$cmd" +echo "" -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\" 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 +start=$(date +%s) - results+=("- $config - duration: ${duration} - result: ${lastCode}") +# prevent non-zero exit code from breaking the loop +set +e +eval "$cmd" +lastCode=$? +set -e - if [ $lastCode -ne 0 ]; then - exitCode=10 - echo "Jest exited with code $lastCode" - echo "^^^ +++" +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 - if [[ "$failedConfigs" ]]; then - failedConfigs="${failedConfigs}"$'\n'"$config" - else - failedConfigs="$config" - 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 -done <<< "$configs" +fi +# done <<< "$configs" if [[ "$failedConfigs" ]]; then buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "$failedConfigs" diff --git a/custom-jest-environment.js b/custom-jest-environment.js new file mode 100644 index 0000000000000..b54af7bfdf0cd --- /dev/null +++ b/custom-jest-environment.js @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +const JSDOMEnvironment = require('jest-environment-jsdom'); +const { screen } = require('@testing-library/react'); + +class CustomEnvironment extends JSDOMEnvironment { + async handleTestEvent(event, state) { + if (event.name === 'test_fn_failure') { + const error = event.test.errors[0]; + if (error && error.message && error.message.includes('Timed out')) { + console.log('Timeout error detected. Current screen state:'); + screen.debug(); + } + } + await super.handleTestEvent(event, state); + } +} + +module.exports = CustomEnvironment; diff --git a/packages/kbn-test/src/jest/setup/disable_console_logs.js b/packages/kbn-test/src/jest/setup/disable_console_logs.js index 8fd061ba7867c..29095b7bd4e4f 100644 --- a/packages/kbn-test/src/jest/setup/disable_console_logs.js +++ b/packages/kbn-test/src/jest/setup/disable_console_logs.js @@ -8,6 +8,6 @@ */ // on CI these logs just muddy up the console and produce a ton of unnecessary noise -console.log = () => {}; -console.error = () => {}; -console.warn = () => {}; +// console.log = () => {}; +// console.error = () => {}; +// console.warn = () => {}; diff --git a/x-pack/plugins/cases/jest.config.js b/x-pack/plugins/cases/jest.config.js index 3b1b0b1223191..baf945dc42fc0 100644 --- a/x-pack/plugins/cases/jest.config.js +++ b/x-pack/plugins/cases/jest.config.js @@ -12,4 +12,5 @@ module.exports = { coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/cases', coverageReporters: ['text', 'html'], collectCoverageFrom: ['/x-pack/plugins/cases/{common,public,server}/**/*.{ts,tsx}'], + testEnvironment: '/custom-jest-environment.js', };