@@ -262,6 +262,54 @@ Error: spec iframe stack
262262 ] )
263263 } )
264264
265+ it ( 'strips webpack protocol and maintains absolute path' , ( ) => {
266+ $sourceMapUtils . getSourcePosition . returns ( {
267+ file : 'cypress:////root/absolute/path/some_other_file.ts' ,
268+ line : 2 ,
269+ column : 1 ,
270+ } )
271+
272+ $sourceMapUtils . getSourcePosition . onCall ( 1 ) . returns ( {
273+ file : 'webpack:////root/absolute/path/cypress/integration/features/source_map_spec.coffee' ,
274+ line : 4 ,
275+ column : 3 ,
276+ } )
277+
278+ const sourceStack = $stackUtils . getSourceStack ( generatedStack , projectRoot )
279+
280+ expect ( sourceStack . sourceMapped ) . to . equal ( `Error: spec iframe stack
281+ at foo.bar (cypress:////root/absolute/path/some_other_file.ts:2:2)
282+ at Context.<anonymous> (webpack:////root/absolute/path/cypress/integration/features/source_map_spec.coffee:4:4)\
283+ ` )
284+
285+ expect ( sourceStack . parsed ) . to . eql ( [
286+ {
287+ message : 'Error: spec iframe stack' ,
288+ whitespace : '' ,
289+ } ,
290+ {
291+ function : 'foo.bar' ,
292+ fileUrl : 'http://localhost:1234/source_map_spec.js' ,
293+ originalFile : 'cypress:////root/absolute/path/some_other_file.ts' ,
294+ relativeFile : '/root/absolute/path/some_other_file.ts' ,
295+ absoluteFile : '/root/absolute/path/some_other_file.ts' ,
296+ line : 2 ,
297+ column : 2 ,
298+ whitespace : ' ' ,
299+ } ,
300+ {
301+ function : 'Context.<anonymous>' ,
302+ fileUrl : 'http://localhost:1234/tests?p=cypress/integration/features/source_map_spec.js' ,
303+ originalFile : 'webpack:////root/absolute/path/cypress/integration/features/source_map_spec.coffee' ,
304+ relativeFile : '/root/absolute/path/cypress/integration/features/source_map_spec.coffee' ,
305+ absoluteFile : '/root/absolute/path/cypress/integration/features/source_map_spec.coffee' ,
306+ line : 4 ,
307+ column : 4 ,
308+ whitespace : ' ' ,
309+ } ,
310+ ] )
311+ } )
312+
265313 it ( 'returns empty object if there\'s no stack' , ( ) => {
266314 expect ( $stackUtils . getSourceStack ( ) ) . to . eql ( { } )
267315 } )
@@ -364,6 +412,27 @@ Error: spec iframe stack
364412 expect ( details . relativeFile ) . to . equal ( 'cypress/integration/spec%with space &^$ emoji👍_你好.js' )
365413 expect ( details . absoluteFile ) . to . equal ( `${ projectRoot } /cypress/integration/spec%with space &^$ emoji👍_你好.js` )
366414 } )
415+
416+ it ( 'maintains absolute path when provided' , ( ) => {
417+ cy . stub ( $sourceMapUtils , 'getSourcePosition' ) . returns ( {
418+ file : '/root/path/cypress/integration/spec.js' ,
419+ line : 1 ,
420+ column : 0 ,
421+ } )
422+
423+ // stack is fairly irrelevant in this test - testing transforming getSourcePosition response
424+ const stack = stripIndent `
425+ Error
426+ at Object../cypress/integration/spec.js (http://localhost:50129/__cypress/tests?p=/root/path/cypress/integration/spec.js:99:1)
427+ `
428+
429+ const projectRoot = '/Users/gleb/git/cypress-example-todomvc'
430+ const details = $stackUtils . getSourceDetailsForFirstLine ( stack , projectRoot )
431+
432+ expect ( details . originalFile ) . to . equal ( '/root/path/cypress/integration/spec.js' )
433+ expect ( details . relativeFile ) . to . equal ( '/root/path/cypress/integration/spec.js' )
434+ expect ( details . absoluteFile ) . to . equal ( `/root/path/cypress/integration/spec.js` )
435+ } )
367436 } )
368437
369438 context ( '.stackWithUserInvocationStackSpliced' , ( ) => {
0 commit comments