Skip to content

Commit 4a02492

Browse files
BridgeARwatson
andauthored
test: migrate tap to mocha (#7135)
* test: migrate tap to mocha This tries to align with the former behavior as close as possible. This is for example the case by using more parallel threads, even if the CPU has less cores. * test: run mocha tests in parallel per file This is adding a script to run multiple mocha test files in parallel in their own child process instead of using mocha's own parallel mode that is using a pool instead of child processes. --------- Co-authored-by: Thomas Watson <thomas.watson@datadoghq.com>
1 parent 28b054c commit 4a02492

151 files changed

Lines changed: 1069 additions & 1139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ updates:
7373
# Thus, we ignore them and update them manually.
7474
- dependency-name: "@opentelemetry/api"
7575
- dependency-name: "@opentelemetry/api-logs"
76-
- dependency-name: "tap"
77-
# Contain breaking changes that are incompatible with our test usage
78-
update-types: ["version-update:semver-major"]
7976
groups:
8077
dev-minor-and-patch-dependencies:
8178
dependency-type: "development"

.taprc

Lines changed: 0 additions & 5 deletions
This file was deleted.

AGENTS.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- Install dependencies: `yarn install`
1212

13-
**Note:** This project uses yarn, not npm. Always use `yarn` commands instead of `npm` commands.
13+
**This project uses yarn, not npm. Always use `yarn` commands instead of `npm` commands.**
1414

1515
## Project Overview
1616

@@ -44,18 +44,13 @@ When developing a feature or fixing a bug:
4444

4545
### Running Individual Tests
4646

47-
**IMPORTANT**: Never run `yarn test` directly. Use `mocha` or `tap` directly on test files.
47+
**IMPORTANT**: Never run `yarn test` directly. Use `mocha` directly on test files.
4848

4949
**Mocha unit tests:**
5050
```bash
5151
./node_modules/.bin/mocha -r "packages/dd-trace/test/setup/mocha.js" path/to/test.spec.js
5252
```
5353

54-
**Tap unit tests:**
55-
```bash
56-
./node_modules/.bin/tap path/to/test.spec.js
57-
```
58-
5954
**Integration tests:**
6055
```bash
6156
./node_modules/.bin/mocha --timeout 60000 -r "packages/dd-trace/test/setup/core.js" path/to/test.spec.js
@@ -67,8 +62,6 @@ When developing a feature or fixing a bug:
6762
**Enable debug logging:**
6863
- Prefix with `DD_TRACE_DEBUG=true`
6964

70-
**Note**: New tests should be written using mocha, not tap. Existing tap tests use mocha-style `describe` and `it` blocks.
71-
7265
### Plugin Tests
7366

7467
**Use `PLUGINS` env var:**

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ Please refer to [the "Install" section](https://github.com/brianc/node-postgres/
290290

291291
When developing, it's often faster to run individual test files rather than entire test suites. **Never run `yarn test` directly** as it requires too much setup and takes too long.
292292

293-
To target specific tests, use the `--grep` flag with mocha or tap to match test names:
293+
To target specific tests, use the `--grep` flag with mocha to match test names:
294294

295295
```sh
296296
yarn test:debugger --grep "test name pattern"
297297
yarn test:appsec --grep "specific test"
298298
```
299299

300-
**Note:** This project uses a mix of tap and mocha for testing. However, new tests should be written using mocha, not tap.
300+
**This project uses mocha for testing.**
301301

302302
### Test Assertions
303303

benchmark/sirun/startup/startup-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ if (Number(process.env.EVERYTHING)) {
6868
'shell-quote',
6969
'sinon',
7070
'source-map',
71-
'tap',
7271
'tiktoken',
7372
'tlhunter-sorted-set',
7473
'ttl-set',

eslint.config.mjs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,32 @@ export default [
406406
'n/no-restricted-require': ['error', [
407407
{
408408
name: 'diagnostics_channel',
409-
message: 'Please use dc-polyfill instead.'
409+
message: 'Please use `dc-polyfill` instead.'
410410
},
411411
{
412412
name: 'semver',
413-
message: 'Please use semifies instead.'
413+
message: 'Please use `semifies` instead.'
414414
},
415415
{
416416
name: 'get-port',
417417
message: 'Please listen on port 0 instead.'
418418
},
419419
{
420420
name: 'rimraf',
421-
message: 'Please use fs.rm(path, { recursive: true, force: true }) instead.'
421+
message: 'Please use `fs.rm(path, { recursive: true, force: true })` instead.'
422422
},
423423
{
424424
name: 'koalas',
425425
message: 'Please use nullish coalescing operator (??) instead.'
426-
}
426+
},
427+
{
428+
name: 'chai',
429+
message: 'Please use `node:assert/strict` instead.'
430+
},
431+
{
432+
name: 'tap',
433+
message: 'Please use `mocha` instead.'
434+
},
427435
]],
428436

429437
'no-await-in-loop': 'error',

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
2929
"test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
3030
"test:eslint-rules": "node eslint-rules/*.test.mjs",
31-
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
32-
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
31+
"test:trace:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 --require packages/dd-trace/test/setup/mocha.js -- \"packages/dd-trace/test/*.spec.js\" \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
32+
"test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" -- npm run test:trace:core",
3333
"test:trace:guardrails": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/guardrails/**/*.spec.js\"",
3434
"test:trace:guardrails:ci": "nyc --no-clean --include \"packages/dd-trace/src/guardrails/**/*.js\" -- npm run test:trace:guardrails",
3535
"test:esbuild": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-esbuild/test/**/*.spec.js\"",
@@ -38,8 +38,8 @@
3838
"test:instrumentations:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" -- npm run test:instrumentations",
3939
"test:instrumentations:misc": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/*/**/*.spec.js'",
4040
"test:instrumentations:misc:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations:misc",
41-
"test:core": "tap \"packages/datadog-core/test/**/*.spec.js\"",
42-
"test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=\"packages/datadog-core/src/**/*.js\"",
41+
"test:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/datadog-core/test/**/*.spec.js\"",
42+
"test:core:ci": "nyc --no-clean --include \"packages/datadog-core/src/**/*.js\" -- npm run test:core",
4343
"test:lambda": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
4444
"test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
4545
"test:llmobs:sdk": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\" ",
@@ -52,8 +52,8 @@
5252
"test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
5353
"test:plugins:ci:flaky": "yarn services && nyc --no-clean --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins -- --bail --retries 2",
5454
"test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
55-
"test:profiler": "tap \"packages/dd-trace/test/profiling/**/*.spec.js\"",
56-
"test:profiler:ci": "npm run test:profiler -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/profiling/**/*.js\"",
55+
"test:profiler": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 --require packages/dd-trace/test/setup/mocha.js -- \"packages/dd-trace/test/profiling/**/*.spec.js\"",
56+
"test:profiler:ci": "nyc --no-clean --include \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:profiler",
5757
"test:integration": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/*.spec.js\"",
5858
"test:integration:aiguard": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/aiguard/*.spec.js\"",
5959
"test:integration:appsec": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/appsec/*.spec.js\"",
@@ -151,7 +151,6 @@
151151
"@types/mocha": "^10.0.10",
152152
"@types/node": "^18.19.106",
153153
"@types/sinon": "^21.0.0",
154-
"@types/tap": "^15.0.12",
155154
"axios": "^1.12.2",
156155
"benchmark": "^2.1.4",
157156
"body-parser": "^2.2.0",
@@ -182,7 +181,6 @@
182181
"semifies": "^1.0.0",
183182
"semver": "^7.7.2",
184183
"sinon": "^21.0.0",
185-
"tap": "^16.3.10",
186184
"tiktoken": "^1.0.21",
187185
"typescript": "^5.9.2",
188186
"workerpool": "^10.0.0",

packages/datadog-code-origin/test/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

3-
const { describe, it, afterEach } = require('tap').mocha
43
const { resolve } = require('node:path')
54
const assert = require('node:assert')
65

7-
require('../../dd-trace/test/setup/core')
6+
const { describe, it, afterEach } = require('mocha')
87

8+
require('../../dd-trace/test/setup/core')
99
const { entryTags, exitTags } = require('../index')
1010
const { getNextLineNumber } = require('../../dd-trace/test/plugins/helpers')
1111

packages/datadog-core/test/storage.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

33
const assert = require('node:assert/strict')
4-
const { describe, it, beforeEach, afterEach } = require('tap').mocha
54
const { executionAsyncResource } = require('async_hooks')
65

7-
require('../../dd-trace/test/setup/core')
6+
const { describe, it, beforeEach, afterEach } = require('mocha')
87

8+
require('../../dd-trace/test/setup/core')
99
const { storage } = require('../src/storage')
1010

1111
describe('storage', () => {

packages/datadog-core/test/utils/src/parse-tags.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22

33
const assert = require('node:assert/strict')
4-
const { describe, it } = require('tap').mocha
54

6-
require('../../../../dd-trace/test/setup/core')
5+
const { describe, it } = require('mocha')
76

7+
require('../../../../dd-trace/test/setup/core')
88
const parseTags = require('../../../src/utils/src/parse-tags')
99

1010
describe('parseTags', () => {

0 commit comments

Comments
 (0)