@@ -9,7 +9,7 @@ const test = require('node:test')
99const assert = require ( 'node:assert' )
1010
1111const { removeModules } = require ( '../../lib/cache-buster' )
12- const { assertPackageMetrics , match } = require ( '../../lib/custom-assertions' )
12+ const { match } = require ( '../../lib/custom-assertions' )
1313const helper = require ( '../../lib/agent_helper' )
1414const testServer = require ( './test-server' )
1515
@@ -33,11 +33,9 @@ test.afterEach(async (ctx) => {
3333 await ctx . nr . stopServer ( )
3434} )
3535
36- test ( 'should log tracking metrics' , function ( t ) {
37- const { agent } = t . nr
38- const { version } = require ( 'superagent/package.json' )
39- assertPackageMetrics ( { agent, pkg : 'superagent' , version } )
40- } )
36+ // We no longer instrument `superagent`, but the tests
37+ // are still here to make sure our new context manager
38+ // is propagating correctly.
4139
4240test ( 'should maintain transaction context with callbacks' , ( t , end ) => {
4341 const { address, agent, request } = t . nr
@@ -49,12 +47,6 @@ test('should maintain transaction context with callbacks', (t, end) => {
4947 const [ mainSegment ] = tx . trace . getChildren ( tx . trace . root . id )
5048 assert . ok ( mainSegment )
5149 match ( mainSegment . name , EXTERNAL_NAME , 'has segment matching request' )
52- const mainChildren = tx . trace . getChildren ( mainSegment . id )
53- assert . equal (
54- mainChildren . filter ( ( c ) => c . name === 'Callback: testCallback' ) . length ,
55- 1 ,
56- 'has segment matching callback'
57- )
5850
5951 end ( )
6052 } )
@@ -78,12 +70,6 @@ test('should maintain transaction context with promises', (t, end) => {
7870 const [ mainSegment ] = tx . trace . getChildren ( tx . trace . root . id )
7971 assert . ok ( mainSegment )
8072 match ( mainSegment . name , EXTERNAL_NAME , 'has segment matching request' )
81- const mainChildren = tx . trace . getChildren ( mainSegment . id )
82- assert . equal (
83- mainChildren . filter ( ( c ) => c . name === 'Callback: <anonymous>' ) . length ,
84- 1 ,
85- 'has segment matching callback'
86- )
8773
8874 end ( )
8975 } )
@@ -97,3 +83,25 @@ test('should not create segment for a promise if not in a transaction', (t, end)
9783 end ( )
9884 } )
9985} )
86+
87+ test ( 'should maintain transaction context with promises, async-await' , ( t , end ) => {
88+ const { address, agent } = t . nr
89+ helper . runInTransaction ( agent , async function ( tx ) {
90+ assert . ok ( tx )
91+
92+ const { request } = t . nr
93+ await request . get ( address )
94+
95+ const [ mainSegment ] = tx . trace . getChildren ( tx . trace . root . id )
96+ assert . ok ( mainSegment )
97+ match ( mainSegment . name , EXTERNAL_NAME , 'has segment matching request' )
98+
99+ end ( )
100+ } )
101+ } )
102+
103+ test ( 'should not create segment if not in a transaction, async-await' , async ( t ) => {
104+ const { address, agent, request } = t . nr
105+ await request . get ( address )
106+ assert . equal ( agent . getTransaction ( ) , undefined , 'should not have a transaction' )
107+ } )
0 commit comments