Skip to content

(feat) Use Jest native test file discovery#103

Merged
anmarchenko merged 3 commits into
mainfrom
sebas_conde/feat/jest_test_discovery_improvement
Jul 2, 2026
Merged

(feat) Use Jest native test file discovery#103
anmarchenko merged 3 commits into
mainfrom
sebas_conde/feat/jest_test_discovery_improvement

Conversation

@cbasitodx

Copy link
Copy Markdown
Contributor

What does this PR do?
Use Jest’s native --listTests command for Jest test file discovery instead of ddtest’s generic glob-based discovery.

Motivation
Jest should decide which files belong to its test suite. Globbing by extension is fragile as ddtest adds more JavaScript test frameworks with overlapping file extensions.

This PR adds a framework-level fast file discovery hook so the planner stays framework-agnostic while Jest can use native discovery. Existing RSpec, Minitest, and PyTest behavior remains unchanged through the generic glob helper.

@cbasitodx cbasitodx added enhancement New feature or request go Pull requests that update go code labels Jul 1, 2026
@anmarchenko anmarchenko marked this pull request as ready for review July 1, 2026 13:45
@anmarchenko anmarchenko requested a review from a team as a code owner July 1, 2026 13:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3512349a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/framework/jest.go Outdated

@juan-fernandez juan-fernandez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think using jest --listTests is a good default, as this will automatically detect custom jest configuration. This should work for most of the cases. There are nastier examples:

  1. jest executable is not available. Maybe ddtest is run before the install step?
  2. the repo is multi-package. In this case, jest --listTests might not work at all because each package might have different configurations

I say let's tackle those later on.

how does ruby do it? do they also rely on the test framework to get the list? Or is it a glob base search?

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

PR successfully adds Jest's native test file discovery via jest --listTests command. Implementation correctly handles path normalization, symlink resolution, and filters non-file output via os.Stat checks. All 20 test suites pass with no regressions. Framework interface abstraction works well, with other frameworks properly delegating to generic discovery helper.

Was this helpful? React 👍 or 👎

📊 Validated against 8 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit e351234 · What is Autotest? · Any feedback? Reach out in #autotest

@cbasitodx

Copy link
Copy Markdown
Contributor Author

@juan-fernandez regarding the first point, I believe ddtest could install Jest if not installed because it falls back to npx jest. The second point I think it's more tricky 😵‍💫

Ruby supports full discovery, so it can either do test file discovery using glob like us before this PR (look at DiscoverTestFiles(...)) or test discovery by using the framework :)

@anmarchenko

Copy link
Copy Markdown
Member

Ruby assumes that test framework is available in the bundle (as well as tracer library)

@cbasitodx

Copy link
Copy Markdown
Contributor Author

E2E Test Report: SUCCESS

Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization)

Test Environment

  • Method: Local Shepherd run with mockdog backend
  • Playground: decap-cms
  • Command: bin/crook run decap-cms --assert decap-cms-ddtest-default --dep ddtest=sebas_conde/feat/jest_test_discovery_improvement --debug
  • Revision tested: 31b24ca (Jest test file discovery is now performed uninstrumented)

Results

Check Result
ddtest PR branch cloned and built PASS
Jest native --listTests discovery executed PASS
Fast discovery found expected test files PASS (81)
Planner selected expected runner count PASS (2)
Test split matched expected shape PASS (41 / 40)
Jest worker execution completed PASS (81 files, 2 workers)
Mockdog CI Visibility report matched assertions PASS (49/49)

Issues Found

An earlier E2E run found that instrumented Jest --listTests discovery emitted an extra CI Visibility session/module plus extra settings/git traffic. That was resolved by running Jest file discovery without the dd-trace CI preload. The final run confirmed the report returned to the expected 2 Jest sessions/modules and no discovery-session pollution.

Verification

The run used local mockdog rather than a real Datadog backend, so Datadog UI verification was not applicable. Backend payload behavior was verified through mockdog assertions:

  • 1755 CI Test Cycle events
  • 1670 tests
  • 81 suites
  • 2 modules
  • 2 sessions
  • Telemetry valid with 3 payloads

Test Methodology

  1. Reviewed the PR scope and selected the Jest ddtest playground because this PR changes Jest fast file discovery.
  2. Ran the existing decap-cms-ddtest-default assertion with debug logging.
  3. Verified planner output from the stashed .testoptimization artifacts.
  4. Verified the mockdog report and assertion results.

This E2E test was performed by Shepherd - autonomous QA agent for Datadog Test Optimization.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 1, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 69.00%
Overall Coverage: 87.57% (-0.33%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 492899a | Docs | Datadog PR Page | Give us feedback!

@cbasitodx cbasitodx force-pushed the sebas_conde/feat/jest_test_discovery_improvement branch from 5ecaaed to 492899a Compare July 2, 2026 12:26
@cbasitodx

Copy link
Copy Markdown
Contributor Author

E2E Test Report: SUCCESS

Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization)

Test Environment

  • Method: Local E2E with decap-cms Jest playground through crook
  • Target: local mockdog
  • Revision tested: 492899ac9dda2367d5ff6897d2bf3c6659b71986
  • ddtest branch: sebas_conde/feat/jest_test_discovery_improvement

Results

Check Status
ddtest built and injected from PR branch PASS
Jest fast discovery used native --listTests PASS
No --testMatch / --test-match was passed to Jest PASS
Shell-style relative --tests-location filtered listed Jest files PASS
ddtest run completed successfully PASS
Test events reached mockdog PASS

Verification

  • Ran decap-cms with DD_TEST_OPTIMIZATION_RUNNER_TESTS_LOCATION=./packages/decap-cms-lib-util/src/**/*.spec.js.
  • Log evidence shows Jest discovery command:
    args="[../../scripts/run-jest-and-exit.js --no-cache --listTests]"
  • Fast discovery found and planned 7 files.
  • Stashed runner/test-files.txt contained exactly the 7 files under packages/decap-cms-lib-util/src/__tests__.
  • Run report:
    • Test files run: 7
    • Result: passed
    • CI Test Cycle: 55 events (46 tests, 7 suites, 1 modules, 1 sessions)
    • Telemetry: valid, 1 sessions, 46 tests
  • Datadog UI was not checked because this validation used local mockdog; mockdog intake verification passed.

Test Methodology

  1. Fetched PR metadata and confirmed the PR head revision.
  2. Selected decap-cms because it is the Jest playground with a ddtest command.
  3. Ran:
    ./bin/crook run decap-cms -c ddtest --dep ddtest=sebas_conde/feat/jest_test_discovery_improvement --debug -e 'DD_TEST_OPTIMIZATION_RUNNER_TESTS_LOCATION=./packages/decap-cms-lib-util/src/**/*.spec.js'
  4. Inspected debug logs and stashed .testoptimization runner files to verify native Jest discovery and ddtest-side filtering.

Issues Found

No issues found.


This E2E test was performed by Shepherd - autonomous QA agent for Datadog Test Optimization.

@anmarchenko anmarchenko merged commit 6b8d320 into main Jul 2, 2026
4 checks passed
@anmarchenko anmarchenko deleted the sebas_conde/feat/jest_test_discovery_improvement branch July 2, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants