Skip to content

[CI] Filter empty jest tests before grouping#242440

Merged
delanni merged 15 commits into
elastic:mainfrom
delanni:filter-empty-jest-tests
Nov 14, 2025
Merged

[CI] Filter empty jest tests before grouping#242440
delanni merged 15 commits into
elastic:mainfrom
delanni:filter-empty-jest-tests

Conversation

@delanni
Copy link
Copy Markdown
Member

@delanni delanni commented Nov 10, 2025

Summary

It seems the jest unit test grouping through ci-stats is broken. It's probably because we no longer run and report empty test configs (after #236549 we skip empty configs), thus CI stats will no longer be able to have an accurate guess as to how long they will take. Calculating with the default guessed config runtimes results in weird buckets. We went from ~23 jest unit test groups to ~53 (again, probably because the empty configs, that would run in a few seconds are counted as if they take a few minutes + overhead).

This PR updates the pick_test_group_run_order logic, such that we no longer ask grouping for the configs that don't contain any test files to run. The result reset the jest unit parallel group count back to 23.

For this, I'm using jest's internal utilities to search for test files, and had to bootstrap the step, so that the resolution doesn't break.

@delanni delanni force-pushed the filter-empty-jest-tests branch from 1ad38bc to 92330cd Compare November 10, 2025 16:45
@delanni delanni force-pushed the filter-empty-jest-tests branch from bb6314d to b2b8aa4 Compare November 11, 2025 13:30
@delanni delanni changed the title wip: filter empty jest tests [CI] Filter empty jest tests before grouping Nov 12, 2025
@delanni delanni added release_note:skip Skip the PR/issue when compiling release notes backport:all-open Backport to all branches that could still receive a release Team:Operations Kibana-Operations Team labels Nov 12, 2025
@delanni delanni marked this pull request as ready for review November 12, 2025 15:30
@delanni delanni requested a review from a team as a code owner November 12, 2025 15:30
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

Comment thread .buildkite/pipeline-utils/ci-stats/get_tests_from_config.ts Outdated
@delanni delanni requested a review from a team as a code owner November 13, 2025 14:12
@delanni delanni requested a review from a team as a code owner November 13, 2025 15:52
@delanni delanni enabled auto-merge (squash) November 13, 2025 16:28
const THIS_PATH =
'src/platform/packages/shared/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts';

const IGNORED_FOLDERS = ['.buildkite/'];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check was getting false positive on the newly added get_tests_from_config.ts

set -euo pipefail

source .buildkite/scripts/common/util.sh
source .buildkite/scripts/bootstrap.sh
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed, so that the jest resolver can interpret our own plugins (such as @kbn/test)

enabled?: Array<string | { [configPath: string]: { queue: string } }>;
}

function getEnabledFtrConfigs(patterns?: string[], solutions?: string[]) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions are just moved to the bottom of the file, so the main function is first

ignore: [...DISABLED_JEST_CONFIGS, '**/node_modules/**'],
})
: [];
const jestUnitConfigs = await filterEmptyJestConfigs(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the core of the change, the rest is just readability refactors

@@ -0,0 +1,79 @@
/*
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elastic/appex-qa - moved this to another file, not to bloat that already big file, most of the functionality doesn't overlap, so I think it's cleaner this way

@delanni delanni requested a review from Copilot November 13, 2025 16:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where Jest unit test grouping via ci-stats became inefficient after empty test configs were excluded from execution. The main change filters out empty Jest configs before requesting grouping, which reduces parallel test groups from ~53 back to the optimal ~23.

Key changes:

  • Introduced filterEmptyJestConfigs function that uses Jest's internal APIs to detect configs with no test files
  • Moved shared utility functions (getRequiredEnv, runBatchedPromises) to common location
  • Refactored Scout test grouping logic into dedicated module for better separation of concerns

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
.buildkite/scripts/steps/test/pick_test_group_run_order.sh Added bootstrap step to support Jest internal utilities resolution
.buildkite/scripts/steps/test/scout_test_run_builder.ts Updated to use refactored Scout grouping function and replaced process.cwd() with getKibanaDir()
.buildkite/pipeline-utils/utils.ts Added shared utility functions getRequiredEnv and runBatchedPromises
.buildkite/pipeline-utils/scout/pick_scout_test_group_run_order.ts Extracted Scout test grouping logic from main file into dedicated module
.buildkite/pipeline-utils/scout/index.ts Export file for Scout utilities
.buildkite/pipeline-utils/index.ts Added Scout module export
.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts Refactored to use filterEmptyJestConfigs, moved helper functions to end of file, updated imports
.buildkite/pipeline-utils/ci-stats/index.ts Added export for new get_tests_from_config module
.buildkite/pipeline-utils/ci-stats/get_tests_from_config.ts New file implementing empty Jest config detection using Jest internal APIs
src/platform/packages/shared/kbn-test/src/functional_test_runner/lib/config/run_check_ftr_configs_cli.ts Added filtering for .buildkite/ folders in config discovery
src/platform/packages/shared/kbn-developer-toolbar/jest.config.js Fixed incorrect path reference from private to shared

Comment thread .buildkite/pipeline-utils/ci-stats/get_tests_from_config.ts
Copy link
Copy Markdown
Member

@csr csr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for looking into the test config grouping and the fix!

@delanni delanni disabled auto-merge November 14, 2025 13:04
@delanni
Copy link
Copy Markdown
Member Author

delanni commented Nov 14, 2025

/ci

Copy link
Copy Markdown
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@delanni delanni enabled auto-merge (squash) November 14, 2025 14:04
@delanni delanni merged commit 4889045 into elastic:main Nov 14, 2025
12 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.19, 9.1, 9.2

https://github.com/elastic/kibana/actions/runs/19369827128

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@kibanamachine
Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts
9.1 Backport failed because of merge conflicts
9.2 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 242440

Questions ?

Please refer to the Backport tool documentation

@delanni delanni added backport:skip This PR does not require backporting and removed backport:all-open Backport to all branches that could still receive a release labels Nov 17, 2025
@delanni
Copy link
Copy Markdown
Member Author

delanni commented Nov 17, 2025

Skipping backport, as the cause wasn't backported

@delanni delanni deleted the filter-empty-jest-tests branch November 17, 2025 10:15
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Dec 2, 2025
## Summary
It seems the jest unit test grouping through `ci-stats` is broken. It's
probably because we no longer run and report empty test configs (after
elastic#236549 we skip empty configs),
thus CI stats will no longer be able to have an accurate guess as to how
long they will take. Calculating with the default guessed config
runtimes results in weird buckets. We went from ~23 jest unit test
groups to ~53 (again, probably because the empty configs, that would run
in a few seconds are counted as if they take a few minutes + overhead).

This PR updates the `pick_test_group_run_order` logic, such that we no
longer ask grouping for the configs that don't contain any test files to
run. The result reset the jest unit parallel group count back to 23.

For this, I'm using jest's internal utilities to search for test files,
and had to bootstrap the step, so that the resolution doesn't break.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
dmlemeshko pushed a commit to dmlemeshko/kibana that referenced this pull request Apr 14, 2026
## Summary
It seems the jest unit test grouping through `ci-stats` is broken. It's
probably because we no longer run and report empty test configs (after
elastic#236549 we skip empty configs),
thus CI stats will no longer be able to have an accurate guess as to how
long they will take. Calculating with the default guessed config
runtimes results in weird buckets. We went from ~23 jest unit test
groups to ~53 (again, probably because the empty configs, that would run
in a few seconds are counted as if they take a few minutes + overhead).

This PR updates the `pick_test_group_run_order` logic, such that we no
longer ask grouping for the configs that don't contain any test files to
run. The result reset the jest unit parallel group count back to 23.

For this, I'm using jest's internal utilities to search for test files,
and had to bootstrap the step, so that the resolution doesn't break.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 4889045)

# Conflicts:
#	.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts
#	.buildkite/pipeline-utils/scout/index.ts
#	.buildkite/pipeline-utils/scout/pick_scout_test_group_run_order.ts
#	.buildkite/pipelines/fips/fips_pipeline.ts
#	.buildkite/scripts/steps/test/pick_test_group_run_order.sh
#	src/platform/packages/shared/kbn-test-saml-auth/jest.config.js
@dmlemeshko
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.2

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Operations Kibana-Operations Team v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants