@@ -24,6 +24,7 @@ import {
24
24
quote ,
25
25
quotePowerShell ,
26
26
randomId ,
27
+ getCallerLocationFromString ,
27
28
} from '../build/util.js'
28
29
29
30
describe ( 'util' , ( ) => {
@@ -92,3 +93,50 @@ describe('util', () => {
92
93
)
93
94
} )
94
95
} )
96
+
97
+ test ( 'getCallerLocation: empty' , ( ) => {
98
+ assert . equal ( getCallerLocationFromString ( ) , 'unknown' )
99
+ } )
100
+
101
+ test ( 'getCallerLocation: no-match' , ( ) => {
102
+ assert . equal ( getCallerLocationFromString ( 'stack\nstring' ) , 'stack\nstring' )
103
+ } )
104
+
105
+ test ( `getCallerLocationFromString-v8` , ( ) => {
106
+ const stack = `
107
+ Error
108
+ at getCallerLocation (/Users/user/test.js:22:17)
109
+ at e (/Users/user/test.js:34:13)
110
+ at d (/Users/user/test.js:11:5)
111
+ at c (/Users/user/test.js:8:5)
112
+ at b (/Users/user/test.js:5:5)
113
+ at a (/Users/user/test.js:2:5)
114
+ at Object.<anonymous> (/Users/user/test.js:37:1)
115
+ at Module._compile (node:internal/modules/cjs/loader:1254:14)
116
+ at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
117
+ at Module.load (node:internal/modules/cjs/loader:1117:32)
118
+ at Module._load (node:internal/modules/cjs/loader:958:12)
119
+ `
120
+ assert . match ( getCallerLocationFromString ( stack ) , / ^ .* : 1 1 : 5 .* $ / )
121
+ } )
122
+
123
+ test ( `getCallerLocationFromString-JSC` , ( ) => {
124
+ const stack = `
125
+ getCallerLocation@/Users/user/test.js:22:17
126
+ e@/Users/user/test.js:34:13
127
+ d@/Users/user/test.js:11:5
128
+ c@/Users/user/test.js:8:5
129
+ b@/Users/user/test.js:5:5
130
+ a@/Users/user/test.js:2:5
131
+ module code@/Users/user/test.js:37:1
132
+ evaluate@[native code]
133
+ moduleEvaluation@[native code]
134
+ moduleEvaluation@[native code]
135
+ @[native code]
136
+ asyncFunctionResume@[native code]
137
+ promiseReactionJobWithoutPromise@[native code]
138
+ promiseReactionJob@[native code]
139
+ d@/Users/user/test.js:11:5
140
+ `
141
+ assert . match ( getCallerLocationFromString ( stack ) , / ^ .* : 1 1 : 5 .* $ / )
142
+ } )
0 commit comments