@@ -3,113 +3,63 @@ import {
33 EXTENSION_PREFIXES ,
44 extractExtensionUrlFromStack ,
55 isUnsupportedExtensionEnvironment ,
6+ STACK_WITH_INIT_IN_PAGE ,
7+ STACK_WITH_INIT_IN_EXTENSION ,
8+ STACK_WITH_INIT_IN_EXTENSION_FIREFOX ,
69} from './extensionUtils'
710
8- describe ( 'containsExtensionUrl' , ( ) => {
9- it ( 'should return true if string contains an extension URL' , ( ) => {
10- EXTENSION_PREFIXES . forEach ( ( prefix ) => {
11- expect ( containsExtensionUrl ( `${ prefix } some/path` ) ) . toBe ( true )
11+ describe ( 'extensionUtils' , ( ) => {
12+ describe ( 'containsExtensionUrl' , ( ) => {
13+ it ( 'should return true if string contains an extension URL' , ( ) => {
14+ EXTENSION_PREFIXES . forEach ( ( prefix ) => {
15+ expect ( containsExtensionUrl ( `${ prefix } some/path` ) ) . toBe ( true )
16+ } )
1217 } )
13- } )
14-
15- it ( 'should return false if string does not contain extension URL' , ( ) => {
16- expect ( containsExtensionUrl ( 'https://example.com' ) ) . toBe ( false )
17- expect ( containsExtensionUrl ( '' ) ) . toBe ( false )
18- } )
19- } )
2018
21- describe ( 'isUnsupportedExtensionEnvironment' , ( ) => {
22- it ( 'should return true when window location is a regular URL and error stack contains extension URL' , ( ) => {
23- expect (
24- isUnsupportedExtensionEnvironment ( 'https://example.com' , 'Error: at chrome-extension://abcdefg/content.js:10:15' )
25- ) . toBe ( true )
19+ it ( 'should return false if string does not contain extension URL' , ( ) => {
20+ expect ( containsExtensionUrl ( 'https://example.com' ) ) . toBe ( false )
21+ expect ( containsExtensionUrl ( '' ) ) . toBe ( false )
22+ } )
2623 } )
2724
28- it ( 'should return false when both window location and error stack are regular URLs' , ( ) => {
29- expect (
30- isUnsupportedExtensionEnvironment ( 'https://example.com' , 'Error: at https://example.com/script.js:10:15' )
31- ) . toBe ( false )
32- } )
25+ describe ( 'isUnsupportedExtensionEnvironment' , ( ) => {
26+ it ( 'should return true when window location is a regular URL and error stack init is in an extension' , ( ) => {
27+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , STACK_WITH_INIT_IN_EXTENSION ) ) . toBe ( true )
28+ } )
3329
34- it ( 'should return false when window location is an extension URL' , ( ) => {
35- EXTENSION_PREFIXES . forEach ( ( prefix ) => {
36- expect (
37- isUnsupportedExtensionEnvironment ( `${ prefix } some/path` , 'Error: at chrome-extension://abcdefg/content.js:10:15' )
38- ) . toBe ( false )
30+ it ( 'should return false when both window location and error stack init are regular URLs' , ( ) => {
31+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , STACK_WITH_INIT_IN_PAGE ) ) . toBe ( false )
3932 } )
40- } )
4133
42- it ( 'should return false when error stack is empty' , ( ) => {
43- expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , '' ) ) . toBe ( false )
44- } )
34+ it ( 'should return false when error stack is empty' , ( ) => {
35+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , '' ) ) . toBe ( false )
36+ } )
4537
46- it ( 'should handle each extension prefix in error stack' , ( ) => {
47- EXTENSION_PREFIXES . forEach ( ( prefix ) => {
48- expect (
49- isUnsupportedExtensionEnvironment ( 'https://example.com' , `Error: at ${ prefix } abcdefg/content.js:10:15` )
50- ) . toBe ( true )
38+ it ( 'should handle each extension prefix in firefox' , ( ) => {
39+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , STACK_WITH_INIT_IN_EXTENSION_FIREFOX ) ) . toBe ( true )
5140 } )
52- } )
5341
54- it ( 'should handle case when stack trace is undefined' , ( ) => {
55- expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' ) ) . toBe ( false )
56- } )
42+ it ( 'should handle case when stack trace is undefined' , ( ) => {
43+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' ) ) . toBe ( false )
44+ } )
5745
58- it ( 'should handle extension stack trace' , ( ) => {
59- expect (
60- isUnsupportedExtensionEnvironment ( 'https://example.com' , 'Error: at chrome-extension://abcdefg/content.js:10:15' )
61- ) . toBe ( true )
46+ it ( 'should handle extension stack trace' , ( ) => {
47+ expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , STACK_WITH_INIT_IN_EXTENSION ) ) . toBe ( true )
48+ } )
6249 } )
63- } )
6450
65- describe ( 'extractExtensionUrlFromStack ' , ( ) => {
66- it ( 'should extract extension URL from stack trace' , ( ) => {
67- const stack = `Error
51+ describe ( 'extract init caller ' , ( ) => {
52+ it ( 'should extract extension URL from stack trace' , ( ) => {
53+ const stack = `Error
6854 at foo (<anonymous>:549:44)
6955 at bar (<anonymous>:701:91)
70- at e.init (chrome-extension://boceobohkgenpcpogecpjlnmnfbdigda/content-script-main.js:1:1009)`
71- expect ( extractExtensionUrlFromStack ( stack ) ) . toBe ( 'chrome-extension://boceobohkgenpcpogecpjlnmnfbdigda' )
72- } )
73-
74- it ( 'should return undefined when no extension URL found' , ( ) => {
75- const stack = 'Error at https://example.com/script.js:10:15'
76- expect ( extractExtensionUrlFromStack ( stack ) ) . toBeUndefined ( )
77- } )
78-
79- describe ( 'isUnsupportedExtensionEnvironment caller-frame' , ( ) => {
80- it ( 'should return true when caller frame is an extension URL' , ( ) => {
81- const stack = [
82- 'Error' ,
83- ' at callMonitored (https://cdn.datadoghq.com/rum.js:10:10)' ,
84- ' at Object.init (https://cdn.datadoghq.com/rum.js:9:5)' ,
85- ' at chrome-extension://abc123/script.js:10:15' ,
86- ' at https://app.example.com/app.js:200:30' ,
87- ] . join ( '\n' )
88- expect ( isUnsupportedExtensionEnvironment ( 'https://example.com' , stack ) ) . toBe ( true )
56+ at e.init (chrome-extension://abcd/content-script-main.js:1:1009)`
57+ expect ( extractExtensionUrlFromStack ( stack ) ) . toBe ( 'chrome-extension://abcd' )
8958 } )
9059
91- it ( 'returns false when extension frames exist but the init caller is not an extension' , ( ) => {
92- const stack = [
93- 'Error' ,
94- ' at callMonitored (https://cdn.datadoghq.com/rum.js:10:10)' ,
95- ' at Object.init (https://cdn.datadoghq.com/rum.js:9:5)' ,
96- ' at https://app.example.com/app.js:3:59' ,
97- ' at Object.apply (chrome-extension://random-extension-id/WXkqOoBd.js:10:4624)' ,
98- ' at https://app.example.com/app.js:200:30' ,
99- ] . join ( '\n' )
100-
101- expect ( isUnsupportedExtensionEnvironment ( 'https://app.example.com' , stack ) ) . toBeFalse ( )
102- } )
103-
104- it ( 'falls back to first non-SDK frame if init frame not found' , ( ) => {
105- const stack = [
106- 'Error' ,
107- ' at someInternal (https://cdn.datadoghq.com/rum.js:10:10)' ,
108- ' at otherInternal (https://cdn.datadoghq.com/rum.js:9:5)' ,
109- ' at chrome-extension://abc123/script.js:10:15' ,
110- ] . join ( '\n' )
111-
112- expect ( isUnsupportedExtensionEnvironment ( 'https://app.example.com' , stack ) ) . toBeTrue ( )
60+ it ( 'should return undefined when no extension URL found' , ( ) => {
61+ const stack = 'Error at https://example.com/script.js:10:15'
62+ expect ( extractExtensionUrlFromStack ( stack ) ) . toBeUndefined ( )
11363 } )
11464 } )
11565} )
0 commit comments