@@ -8,39 +8,39 @@ describe('proxy configs', () => {
88 const output = rewriteScriptUrls ( input , [
99 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
1010 ] )
11- expect ( output ) . toBe ( `fetch("/_scripts/c/ga/g/collect")` )
11+ expect ( output ) . toBe ( `fetch(self.location.origin+ "/_scripts/c/ga/g/collect")` )
1212 } )
1313
1414 it ( 'rewrites https URLs with single quotes' , ( ) => {
1515 const input = `url='https://www.google-analytics.com/analytics.js'`
1616 const output = rewriteScriptUrls ( input , [
1717 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
1818 ] )
19- expect ( output ) . toBe ( `url='/_scripts/c/ga/analytics.js'` )
19+ expect ( output ) . toBe ( `url=self.location.origin+ '/_scripts/c/ga/analytics.js'` )
2020 } )
2121
2222 it ( 'rewrites https URLs with backticks' , ( ) => {
2323 const input = 'const u=`https://www.google-analytics.com/collect`'
2424 const output = rewriteScriptUrls ( input , [
2525 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
2626 ] )
27- expect ( output ) . toBe ( 'const u=`/_scripts/c/ga/collect`' )
27+ expect ( output ) . toBe ( 'const u=self.location.origin+ `/_scripts/c/ga/collect`' )
2828 } )
2929
3030 it ( 'rewrites protocol-relative URLs' , ( ) => {
3131 const input = `"//www.google-analytics.com/analytics.js"`
3232 const output = rewriteScriptUrls ( input , [
3333 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
3434 ] )
35- expect ( output ) . toBe ( `"/_scripts/c/ga/analytics.js"` )
35+ expect ( output ) . toBe ( `self.location.origin+ "/_scripts/c/ga/analytics.js"` )
3636 } )
3737
3838 it ( 'rewrites http URLs' , ( ) => {
3939 const input = `"http://www.google-analytics.com/analytics.js"`
4040 const output = rewriteScriptUrls ( input , [
4141 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
4242 ] )
43- expect ( output ) . toBe ( `"/_scripts/c/ga/analytics.js"` )
43+ expect ( output ) . toBe ( `self.location.origin+ "/_scripts/c/ga/analytics.js"` )
4444 } )
4545
4646 it ( 'handles multiple rewrites in single content' , ( ) => {
@@ -52,24 +52,24 @@ describe('proxy configs', () => {
5252 { from : 'www.google-analytics.com' , to : '/_scripts/c/ga' } ,
5353 { from : 'analytics.google.com' , to : '/_scripts/c/ga' } ,
5454 ] )
55- expect ( output ) . toContain ( `"/_scripts/c/ga/g/collect"` )
56- expect ( output ) . toContain ( `"/_scripts/c/ga/collect"` )
55+ expect ( output ) . toContain ( `self.location.origin+ "/_scripts/c/ga/g/collect"` )
56+ expect ( output ) . toContain ( `self.location.origin+ "/_scripts/c/ga/collect"` )
5757 } )
5858
5959 it ( 'handles GTM URLs' , ( ) => {
6060 const input = `src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXX"`
6161 const output = rewriteScriptUrls ( input , [
6262 { from : 'www.googletagmanager.com' , to : '/_scripts/c/gtm' } ,
6363 ] )
64- expect ( output ) . toBe ( `src="/_scripts/c/gtm/gtm.js?id=GTM-XXXX"` )
64+ expect ( output ) . toBe ( `src=self.location.origin+ "/_scripts/c/gtm/gtm.js?id=GTM-XXXX"` )
6565 } )
6666
6767 it ( 'handles Meta Pixel URLs' , ( ) => {
6868 const input = `"https://connect.facebook.net/en_US/fbevents.js"`
6969 const output = rewriteScriptUrls ( input , [
7070 { from : 'connect.facebook.net' , to : '/_scripts/c/meta' } ,
7171 ] )
72- expect ( output ) . toBe ( `"/_scripts/c/meta/en_US/fbevents.js"` )
72+ expect ( output ) . toBe ( `self.location.origin+ "/_scripts/c/meta/en_US/fbevents.js"` )
7373 } )
7474
7575 it ( 'does not rewrite bare domain strings without fromPath' , ( ) => {
0 commit comments