Skip to content

Commit fdb5f32

Browse files
committed
docs: add JavaScript Jest ddtest usage
1 parent 4d38157 commit fdb5f32

3 files changed

Lines changed: 65 additions & 9 deletions

File tree

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ Currently supported:
1414
- Ruby with RSpec or Minitest.
1515
- Python with pytest.
1616
- JavaScript with Jest.
17+
- JavaScript with Jest.
1718

1819
## Prerequisites
1920

2021
Before using DDTest, you must have **Datadog Test Optimization** already set up and enabled with a Datadog Test Optimization library for your language and framework. DDTest relies on this integration to discover your tests and plan test execution accordingly.
2122

23+
Minimum supported library and runtime requirements:
2224
Minimum supported library and runtime requirements:
2325

2426
- Ruby requires the `datadog-ci` gem **1.31.0** or higher.
2527
- Python requires the `ddtrace` package **4.10.3** or higher and `pytest`.
26-
- JavaScript requires Node.js, Jest, and the `dd-trace` package with
27-
`dd-trace/ci/init` available.
28+
- JavaScript requires the `dd-trace` package **6.0.0** or higher, Node.js, and
29+
Jest.
2830

2931
For instructions on setting up Test Optimization, see the [Datadog Test Optimization documentation](https://docs.datadoghq.com/tests/setup/).
3032

@@ -79,6 +81,16 @@ ddtest plan \
7981
--max-parallelism 32
8082
```
8183

84+
For JavaScript/Jest:
85+
86+
```bash
87+
ddtest plan \
88+
--platform javascript \
89+
--framework jest \
90+
--min-parallelism 8 \
91+
--max-parallelism 32
92+
```
93+
8294
This prepares the plan and writes it to `.testoptimization/` folder for later reuse.
8395
Copy `.testoptimization/` to any CI job that runs `ddtest run` or reads DDTest's
8496
plan file lists. For the full file layout and formats, see
@@ -106,6 +118,12 @@ For JavaScript/Jest:
106118
ddtest run --platform javascript --framework jest
107119
```
108120

121+
For JavaScript/Jest:
122+
123+
```bash
124+
ddtest run --platform javascript --framework jest
125+
```
126+
109127
For CI-node mode, worker environment variables, custom commands, and
110128
parallelism details, see [Running DDTest](docs/running.md).
111129

@@ -116,6 +134,9 @@ parallelism details, see [Running DDTest](docs/running.md).
116134
| `--platform` | Language/platform. Currently supported: `ruby`, `python`, `javascript`. |
117135
| `--framework` | Test framework. Currently supported: `rspec`, `minitest`, `pytest`, `jest`. |
118136
| `--command` | Override the default base command for supported framework modes. Currently used by RSpec and Minitest run/discovery, and Jest run/discovery. For pytest, use `PYTEST_ADDOPTS` for pytest flags. |
137+
| `--platform` | Language/platform. Currently supported: `ruby`, `python`, `javascript`. |
138+
| `--framework` | Test framework. Currently supported: `rspec`, `minitest`, `pytest`, `jest`. |
139+
| `--command` | Override the default base command for supported framework modes. Currently used by RSpec and Minitest run/discovery, and Jest run/discovery. For pytest, use `PYTEST_ADDOPTS` for pytest flags. |
119140
| `--min-parallelism` | Minimum CI node or worker count DDTest considers when planning. |
120141
| `--max-parallelism` | Maximum CI node or worker count DDTest considers when planning. |
121142
| `--target-time` | Target wall time DDTest tries to satisfy when selecting parallelism. |

docs/best_practices.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
## Optimize Planning Step
44

55
When using ddtest, you need to add a planning step that performs test discovery
6-
(for example, RSpec dry-run, pytest collection, or Jest `--listTests`) before
7-
execution. This stage adds overhead: you can optimize it with the practices
8-
below.
6+
before execution. For Ruby and Python, this can involve full framework
7+
discovery such as RSpec dry-run or pytest collection. For Jest, DDTest uses
8+
Jest's `--listTests` command to discover test files. This planning stage adds
9+
overhead: you can optimize it with the practices below.
910

1011
### Preinstall System Dependencies Via Docker
1112

@@ -50,6 +51,15 @@ For GitHub Actions + npm:
5051
cache: npm
5152
```
5253
54+
For GitHub Actions + npm:
55+
56+
```yaml
57+
- uses: actions/setup-node@v4
58+
with:
59+
node-version: "22"
60+
cache: npm
61+
```
62+
5363
### Disable Seeds/Fixtures During Discovery
5464
5565
Discovery (planning) does not execute tests; you don't have to setup DB,
@@ -135,6 +145,8 @@ the cache when files under the current project's test root changed. For example,
135145
the default RSpec root is `spec/**`, the default Minitest root is `test/**`,
136146
pytest uses `testpaths` from pytest config when available, and Jest uses the
137147
project's Jest test matching unless `--tests-location` is set. With
148+
pytest uses `testpaths` from pytest config when available, and Jest uses the
149+
project's Jest test matching unless `--tests-location` is set. With
138150
`--tests-location custom/spec/**/*_spec.rb`, the root is `custom/**`.
139151

140152
In monorepos, run DDTest from the project subdirectory whose tests you are
@@ -175,6 +187,29 @@ where DDTest runs.
175187
Jest support uses suite-level Test Impact Analysis. DDTest discovers and splits
176188
test files/suites, not individual Jest tests.
177189

190+
## Jest Support
191+
192+
DDTest runs Jest through the local `node_modules/.bin/jest` executable when it
193+
exists, or through `npx jest` otherwise. During planning it appends
194+
`--listTests`; during execution it appends `--runTestsByPath` and the selected
195+
test files.
196+
197+
Use `--command` when your project runs Jest through a package manager or wrapper:
198+
199+
```bash
200+
ddtest run --platform javascript --framework jest --command "pnpm jest --runInBand"
201+
```
202+
203+
Do not include test files or a `--` separator in the command; DDTest appends the
204+
file list and Jest flags itself.
205+
206+
DDTest prepends `-r dd-trace/ci/init` to `NODE_OPTIONS` for worker processes
207+
unless it is already present, so `dd-trace` must be resolvable from the project
208+
where DDTest runs.
209+
210+
Jest support uses suite-level Test Impact Analysis. DDTest discovers and splits
211+
test files/suites, not individual Jest tests.
212+
178213
## Minitest Support In Non-Rails Projects
179214

180215
We use `bundle exec rake test` command when we don't detect `rails` command to

docs/upgrade-1.0.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ Before upgrading to 1.0, update CI jobs and custom integrations to consume the
66

77
## Required Changes
88

9+
Minimum supported library and runtime requirements:
910
Minimum supported library and runtime requirements:
1011

1112
- Ruby requires the `datadog-ci` gem 1.31.0 or higher.
1213
- Python requires the `ddtrace` package 4.10.3 or higher and `pytest`.
13-
- JavaScript requires Node.js, Jest, and the `dd-trace` package with
14-
`dd-trace/ci/init` available.
14+
- JavaScript requires the `dd-trace` package 6.0.0 or higher, Node.js, and
15+
Jest.
1516

1617
DDTest 1.0 writes plan files under `.testoptimization/runner/*`. If your
1718
scripts, CI jobs, or custom test runners read DDTest plan files directly, update
@@ -28,8 +29,7 @@ these paths:
2829

2930
1. Verify the Datadog Test Optimization library version for your platform:
3031
`datadog-ci` 1.31.0 or higher for Ruby, or `ddtrace` 4.10.3 or higher for
31-
Python. For JavaScript, verify that `dd-trace` is installed and that
32-
`dd-trace/ci/init` is resolvable from the project root.
32+
Python, or `dd-trace` 6.0.0 or higher for JavaScript.
3333
2. Remove references to legacy root plan paths from CI templates and custom scripts.
3434
3. Run `ddtest plan` in CI.
3535
4. Run one CI shard with `DD_TEST_OPTIMIZATION_RUNNER_CI_NODE=0 ddtest run`.

0 commit comments

Comments
 (0)