@@ -6,7 +6,6 @@ const path = require('path')
66
77const proxyquire = require ( 'proxyquire' )
88
9- const { getCallsiteFrames } = require ( '../../../src/appsec/stack_trace' )
109class CallSiteMock {
1110 constructor ( fileName , lineNumber , columnNumber = 0 ) {
1211 this . file = fileName
@@ -26,10 +25,12 @@ describe('path-line', function () {
2625 const firstSep = tmpdir . indexOf ( path . sep )
2726 const rootPath = tmpdir . slice ( 0 , firstSep + 1 )
2827
29- const DIAGNOSTICS_CHANNEL_PATHS = [
28+ const EXCLUDED_TEST_PATHS = [
3029 path . join ( rootPath , 'path' , 'node_modules' , 'dc-polyfill' ) ,
3130 'node:diagnostics_channel' ,
32- 'diagnostics_channel' ,
31+ 'node:fs' ,
32+ 'node:events' ,
33+ 'node:internal/async_local_storage' ,
3334 ]
3435 let mockPath , pathLine , mockProcess
3536
@@ -42,20 +43,20 @@ describe('path-line', function () {
4243 } )
4344 } )
4445
45- describe ( 'getNonDDCallSiteFrames ' , ( ) => {
46+ describe ( 'getCallSiteFramesForLocation ' , ( ) => {
4647 describe ( 'does not fail' , ( ) => {
4748 it ( 'with null parameter' , ( ) => {
48- const result = pathLine . getNonDDCallSiteFrames ( null )
49+ const result = pathLine . getCallSiteFramesForLocation ( null )
4950 assert . deepStrictEqual ( result , [ ] )
5051 } )
5152
5253 it ( 'with empty list parameter' , ( ) => {
53- const result = pathLine . getNonDDCallSiteFrames ( [ ] )
54+ const result = pathLine . getCallSiteFramesForLocation ( [ ] )
5455 assert . deepStrictEqual ( result , [ ] )
5556 } )
5657
5758 it ( 'without parameter' , ( ) => {
58- const result = pathLine . getNonDDCallSiteFrames ( )
59+ const result = pathLine . getCallSiteFramesForLocation ( )
5960 assert . deepStrictEqual ( result , [ ] )
6061 } )
6162 } )
@@ -91,7 +92,7 @@ describe('path-line', function () {
9192 callsites . push ( new CallSiteMock ( firstFileOutOfDD , 13 , 42 ) )
9293 callsites . push ( new CallSiteMock ( secondFileOutOfDD , 20 , 15 ) )
9394
94- const results = pathLine . getNonDDCallSiteFrames ( callsites )
95+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
9596
9697 assert . strictEqual ( results . length , 2 )
9798
@@ -104,17 +105,19 @@ describe('path-line', function () {
104105 assert . strictEqual ( results [ 1 ] . column , 15 )
105106 } )
106107
107- it ( 'should return an empty array when all stack frames are in dd trace' , ( ) => {
108+ it ( 'should fallback to all processed frames when all stack frames are in dd trace' , ( ) => {
108109 const callsites = [ ]
109110 callsites . push ( new CallSiteMock ( PATH_AND_LINE_PATH , PATH_AND_LINE_LINE ) )
110111 callsites . push ( new CallSiteMock ( path . join ( DD_BASE_PATH , 'other' , 'file' , 'in' , 'dd.js' ) , 89 ) )
111112 callsites . push ( new CallSiteMock ( path . join ( DD_BASE_PATH , 'another' , 'file' , 'in' , 'dd.js' ) , 5 ) )
112113
113- const results = pathLine . getNonDDCallSiteFrames ( callsites )
114- assert . deepStrictEqual ( results , [ ] )
114+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
115+
116+ assert . strictEqual ( results . length , 3 )
117+ assert . ok ( results . every ( r => r . path && typeof r . isInternal === 'boolean' ) )
115118 } )
116119
117- DIAGNOSTICS_CHANNEL_PATHS . forEach ( ( dcPath ) => {
120+ EXCLUDED_TEST_PATHS . forEach ( ( dcPath ) => {
118121 it ( `should exclude ${ dcPath } from the results` , ( ) => {
119122 const callsites = [ ]
120123 const expectedFilePath = path . join ( 'first' , 'file' , 'out' , 'of' , 'dd.js' )
@@ -125,7 +128,7 @@ describe('path-line', function () {
125128 callsites . push ( new CallSiteMock ( dcPath , 25 ) )
126129 callsites . push ( new CallSiteMock ( firstFileOutOfDD , 13 , 42 ) )
127130
128- const results = pathLine . getNonDDCallSiteFrames ( callsites )
131+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
129132 assert . strictEqual ( results . length , 1 )
130133
131134 assert . strictEqual ( results [ 0 ] . path , expectedFilePath )
@@ -167,7 +170,7 @@ describe('path-line', function () {
167170 callsites . push ( new CallSiteMock ( firstFileOutOfDD , 13 , 42 ) )
168171 callsites . push ( new CallSiteMock ( secondFileOutOfDD , 20 , 15 ) )
169172
170- const results = pathLine . getNonDDCallSiteFrames ( callsites )
173+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
171174 assert . strictEqual ( results . length , 2 )
172175
173176 assert . strictEqual ( results [ 0 ] . path , expectedFilePaths [ 0 ] )
@@ -230,7 +233,7 @@ describe('path-line', function () {
230233 callsites . push ( new CallSiteMock ( path . join ( PROJECT_PATH , bundleOutFile ) , 3 ) )
231234 callsites . push ( new CallSiteMock ( path . join ( PROJECT_PATH , bundleOutFile ) , 4 , 71 ) )
232235
233- const results = pathLine . getNonDDCallSiteFrames ( callsites )
236+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
234237 assert . strictEqual ( results . length , 2 )
235238
236239 assert . strictEqual ( results [ 0 ] . path , 'file.js' )
@@ -275,7 +278,7 @@ describe('path-line', function () {
275278 callsites . push ( new CallSiteMock ( path . join ( OUT_BUILD_PATH , bundleOutFile ) , 3 , 14 ) )
276279 callsites . push ( new CallSiteMock ( path . join ( OUT_BUILD_PATH , bundleOutFile ) , 2 , 71 ) )
277280
278- const results = pathLine . getNonDDCallSiteFrames ( callsites )
281+ const results = pathLine . getCallSiteFramesForLocation ( callsites )
279282 assert . strictEqual ( results . length , 4 )
280283
281284 assert . strictEqual ( results [ 0 ] . path , bundleOutFile )
@@ -297,35 +300,12 @@ describe('path-line', function () {
297300 } )
298301
299302 describe ( 'getNodeModulesPaths' , ( ) => {
300- function getCallSiteInfo ( ) {
301- const previousPrepareStackTrace = Error . prepareStackTrace
302- const previousStackTraceLimit = Error . stackTraceLimit
303- let callsiteList
304- Error . stackTraceLimit = 100
305- Error . prepareStackTrace = function ( _ , callsites ) {
306- callsiteList = callsites
307- }
308- const e = new Error ( )
309- e . stack
310- Error . prepareStackTrace = previousPrepareStackTrace
311- Error . stackTraceLimit = previousStackTraceLimit
312-
313- return callsiteList
314- }
315-
316303 it ( 'should handle windows paths correctly' , ( ) => {
317- const basePath = pathLine . ddBasePath
318- pathLine . ddBasePath = path . join ( 'test' , 'base' , 'path' )
319-
320- const list = getCallsiteFrames ( 32 , getCallSiteInfo , getCallSiteInfo )
321- const firstNonDDPath = pathLine . getNonDDCallSiteFrames ( list ) [ 0 ]
322-
323- const expectedPath = path . join ( 'node_modules' , firstNonDDPath . path )
324- const nodeModulesPaths = pathLine . getNodeModulesPaths ( firstNonDDPath . path )
304+ const testPath = 'some/nested/path/file.js'
305+ const expectedPath = path . join ( 'node_modules' , 'some' , 'nested' , 'path' , 'file.js' )
306+ const nodeModulesPaths = pathLine . getNodeModulesPaths ( testPath )
325307
326308 assert . strictEqual ( nodeModulesPaths [ 0 ] , expectedPath )
327-
328- pathLine . ddBasePath = basePath
329309 } )
330310
331311 it ( 'should convert / to \\ in windows platforms' , ( ) => {
0 commit comments