Skip to content

Commit

Permalink
[DI] Switch unit tests to Mocha instead of Tap
Browse files Browse the repository at this point in the history
The reason for the change are that Tap has several bugs and drawbacks

- It throws nasty native stack trace when assertions fail in certain
  async situations.
- Doesn't show nice diff of expected vs actual data in deeply nested
  object assertions.
- No support for `.only` when using the Mocha-syntax variant.
- Output from console.logs interfere with the Tap output. It's often
  interweaved, cut off i the middle of a string or mis-colored (probably
  because of multi-threading).
  • Loading branch information
watson committed Sep 26, 2024
1 parent 37af606 commit 3777165
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
"test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
"test:debugger": "tap packages/dd-trace/test/debugger/**/*.spec.js",
"test:debugger:ci": "npm run test:debugger -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/debugger/**/*.js\"",
"test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
"test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
"test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
Expand Down
16 changes: 8 additions & 8 deletions packages/dd-trace/test/debugger/devtools_client/status.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

require('../../setup/tap')
require('../../setup/mocha')

const ddsource = 'dd_debugger'
const service = 'my-service'
const runtimeId = 'my-runtime-id'

describe('diagnostic message http request caching', () => {
describe('diagnostic message http request caching', function () {
let statusproxy, request

const acks = [
Expand All @@ -16,7 +16,7 @@ describe('diagnostic message http request caching', () => {
['ackError', 'ERROR', new Error('boom')]
]

beforeEach(() => {
beforeEach(function () {
request = sinon.spy()
request['@noCallThru'] = true

Expand All @@ -27,10 +27,10 @@ describe('diagnostic message http request caching', () => {
})

for (const [ackFnName, status, err] of acks) {
describe(ackFnName, () => {
describe(ackFnName, function () {
let ackFn, exception

beforeEach(() => {
beforeEach(function () {
if (err) {
ackFn = statusproxy[ackFnName].bind(null, err)
// Use `JSON.stringify` to remove any fields that are `undefined`
Expand All @@ -45,7 +45,7 @@ describe('diagnostic message http request caching', () => {
}
})

it('should only call once if no change', () => {
it('should only call once if no change', function () {
ackFn({ id: 'foo', version: 0 })
expect(request).to.have.been.calledOnce
assertRequestData(request, { probeId: 'foo', version: 0, status, exception })
Expand All @@ -54,7 +54,7 @@ describe('diagnostic message http request caching', () => {
expect(request).to.have.been.calledOnce
})

it('should call again if version changes', () => {
it('should call again if version changes', function () {
ackFn({ id: 'foo', version: 0 })
expect(request).to.have.been.calledOnce
assertRequestData(request, { probeId: 'foo', version: 0, status, exception })
Expand All @@ -64,7 +64,7 @@ describe('diagnostic message http request caching', () => {
assertRequestData(request, { probeId: 'foo', version: 1, status, exception })
})

it('should call again if probeId changes', () => {
it('should call again if probeId changes', function () {
ackFn({ id: 'foo', version: 0 })
expect(request).to.have.been.calledOnce
assertRequestData(request, { probeId: 'foo', version: 0, status, exception })
Expand Down

0 comments on commit 3777165

Please sign in to comment.