11'use strict'
22
3+ const assert = require ( 'node:assert/strict' )
4+
35const axios = require ( 'axios' )
46const { expect } = require ( 'chai' )
57const dc = require ( 'dc-polyfill' )
6- const { describe , it , beforeEach, before , after } = require ( 'mocha' )
8+ const { after , before , beforeEach, describe , it } = require ( 'mocha' )
79const sinon = require ( 'sinon' )
810
9- const agent = require ( '../../dd-trace/test/plugins/agent' )
1011const { storage } = require ( '../../datadog-core' )
12+ const agent = require ( '../../dd-trace/test/plugins/agent' )
1113const { withVersions } = require ( '../../dd-trace/test/setup/mocha' )
12-
1314withVersions ( 'body-parser' , 'body-parser' , version => {
1415 describe ( 'body parser instrumentation' , ( ) => {
1516 const bodyParserReadCh = dc . channel ( 'datadog:body-parser:read:finish' )
@@ -46,8 +47,8 @@ withVersions('body-parser', 'body-parser', version => {
4647 it ( 'should not abort the request by default' , async ( ) => {
4748 const res = await axios . post ( `http://localhost:${ port } /` , { key : 'value' } )
4849
49- expect ( middlewareProcessBodyStub ) . to . be . calledOnce
50- expect ( res . data ) . to . be . equal ( 'DONE' )
50+ sinon . assert . calledOnce ( middlewareProcessBodyStub )
51+ assert . strictEqual ( res . data , 'DONE' )
5152 } )
5253
5354 it ( 'should not abort the request with non blocker subscription' , async ( ) => {
@@ -56,8 +57,8 @@ withVersions('body-parser', 'body-parser', version => {
5657
5758 const res = await axios . post ( `http://localhost:${ port } /` , { key : 'value' } )
5859
59- expect ( middlewareProcessBodyStub ) . to . be . calledOnce
60- expect ( res . data ) . to . be . equal ( 'DONE' )
60+ sinon . assert . calledOnce ( middlewareProcessBodyStub )
61+ assert . strictEqual ( res . data , 'DONE' )
6162
6263 bodyParserReadCh . unsubscribe ( noop )
6364 } )
@@ -72,7 +73,7 @@ withVersions('body-parser', 'body-parser', version => {
7273 const res = await axios . post ( `http://localhost:${ port } /` , { key : 'value' } )
7374
7475 expect ( middlewareProcessBodyStub ) . not . to . be . called
75- expect ( res . data ) . to . be . equal ( 'BLOCKED' )
76+ assert . strictEqual ( res . data , 'BLOCKED' )
7677
7778 bodyParserReadCh . unsubscribe ( blockRequest )
7879 } )
@@ -89,12 +90,12 @@ withVersions('body-parser', 'body-parser', version => {
8990
9091 const res = await axios . post ( `http://localhost:${ port } /` , { key : 'value' } )
9192
92- expect ( store ) . to . have . property ( ' req' , payload . req )
93- expect ( store ) . to . have . property ( ' res' , payload . res )
94- expect ( store ) . to . have . property ( 'span' )
93+ assert . strictEqual ( store . req , payload . req )
94+ assert . strictEqual ( store . res , payload . res )
95+ assert . ok ( Object . hasOwn ( store , 'span' ) )
9596
96- expect ( middlewareProcessBodyStub ) . to . be . calledOnce
97- expect ( res . data ) . to . be . equal ( 'DONE' )
97+ sinon . assert . calledOnce ( middlewareProcessBodyStub )
98+ assert . strictEqual ( res . data , 'DONE' )
9899
99100 bodyParserReadCh . unsubscribe ( handler )
100101 } )
0 commit comments