@@ -136,121 +136,70 @@ describe("Rewriting Domains", function() {
136136 assert . equal ( actual , expected ) ;
137137 } ) ;
138138 it ( "should use the regex to replace links that contain hashes (2)" , function ( ) {
139- var getBase = function ( host ) {
140- return `
141- <ul class="navigation__items">
142- <li class="navigation__items__page">
143- <a href="${ host } /careers/?number=4">« Previous</a>
144- </li>
145- <li class="navigation__items__page">
146- <a href="${ host } /careers/#search">1</a>
147- </li>
148- <li class="navigation__items__page">
149- <a href="${ host } /careers/?number=2#search">2</a>
150- </li>
151- <li class="navigation__items__page">
152- <a href="${ host } /careers/?number=3#search">3</a>
153- </li>
154- <li class="navigation__items__page">
155- <a href="${ host } /careers/?number=4#search">4</a>
156- </li>
157- <li class="navigation__items__page navigation__items__page--active">
158- <a href="${ host } /careers/?number=5#search">5</a>
159- </li>
160- </ul>
161- ` ;
162- } ;
163- var original = getBase ( "http://www.example.local.colinr.com" ) ;
164- var expected = getBase ( "//" + proxyUrl ) ;
139+ var input = fs . readFileSync ( 'test/fixtures/rewrites/hashes.input.html' , 'utf8' ) ;
140+ var expected = fs . readFileSync ( 'test/fixtures/rewrites/hashes.expected.html' , 'utf8' ) ;
165141 var rewrite = utils . rewriteLinks ( { hostname : "www.example.local.colinr.com" , port : 80 } , proxyUrl ) ;
166142 var bound = rewrite . fn . bind ( null , { headers :{ host :proxyUrl } } , { } ) ;
167- var actual = original . replace ( rewrite . match , bound ) ;
143+ var actual = input . replace ( rewrite . match , bound ) ;
168144 assert . equal ( actual , expected ) ;
169145 } ) ;
170146 it ( "should use the regex to replace links that contain port + " , function ( ) {
171- var input = `
172- <!--//<a href="http://example.com:1234/foo">Link 1</a>-->
173- <a href="http://example.com.gov/foo">Link 1</a>
174- ` ;
175- var expected = `
176- <!--//<a href="//${ proxyUrl } /foo">Link 1</a>-->
177- <a href="http://example.com.gov/foo">Link 1</a>
178- ` ;
147+ var input = '<!--//<a href="http://example.com:1234/foo">Link 1</a>--><a href="http://example.com.gov/foo">Link 1</a>' ;
148+ var expected = '<!--//<a href="//192.168.0.4:3002/foo">Link 1</a>--><a href="http://example.com.gov/foo">Link 1</a>' ;
179149
180150 var rewrite = utils . rewriteLinks ( { hostname : "example.com" , port : 1234 } , proxyUrl ) ;
181151 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
182152 var actual = input . replace ( rewrite . match , bound ) ;
183-
184153 assert . equal ( actual , expected ) ;
185154 } ) ;
186- it ( "should use the regex to replace links that contain port + " , function ( ) {
187- var input = `
188- <!doctype html>
189- <html><body>
190- <p>This is an experiment.dev</p>
191- <p><img src="/images/experiment.dev/example.jpg"></p>
192- <!-- This experiment.dev should prove interesting -->
193- <p><a href="http://experiment.dev/example.html">Link</a></p>
194- </body></html>
195- ` ;
196- var expected = `
197- <!doctype html>
198- <html><body>
199- <p>This is an experiment.dev</p>
200- <p><img src="/images/experiment.dev/example.jpg"></p>
201- <!-- This experiment.dev should prove interesting -->
202- <p><a href="//${ proxyUrl } /example.html">Link</a></p>
203- </body></html>
204- ` ;
205-
155+ it ( "should use the regex to replace links + comments" , function ( ) {
156+ var input = fs . readFileSync ( 'test/fixtures/rewrites/comment.html' , 'utf8' ) ;
157+ var expected = fs . readFileSync ( 'test/fixtures/rewrites/comment.expected.html' , 'utf8' ) ;
206158 var rewrite = utils . rewriteLinks ( { hostname : "experiment.dev" } , proxyUrl ) ;
207159 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
208160 var actual = input . replace ( rewrite . match , bound ) ;
209161 assert . equal ( actual , expected ) ;
210162 } ) ;
211163 it ( "should use the regex to replace links that contain port + " , function ( ) {
212- var input = `
213- <link href="/sites/default/themes/mclinic/css/styles.css" media="screen" rel="stylesheet">
214- ` ;
215-
164+ var input = '<link href="/sites/default/themes/mclinic/css/styles.css" media="screen" rel="stylesheet">' ;
216165 var rewrite = utils . rewriteLinks ( { hostname : "mclinic" } , proxyUrl ) ;
217166 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
218167 var actual = input . replace ( rewrite . match , bound ) ;
219168 assert . equal ( actual , input ) ;
220169 } ) ;
221170 it ( "should not replace when host + subdomain " , function ( ) {
222- var input = ` <a href="http://assets.cdn.example.com:1234/foo">Link 1</a>` ;
171+ var input = ' <a href="http://assets.cdn.example.com:1234/foo">Link 1</a>' ;
223172 var rewrite = utils . rewriteLinks ( { hostname : "example.com" , port : 1234 } , proxyUrl ) ;
224173 var actual = input . replace ( rewrite . match , rewrite . fn ) ;
225174 assert . equal ( actual , input ) ;
226175 } ) ;
227176 it ( "should not remove trailing slash" , function ( ) {
228- var input = ` <a href="http://example.com:1234/foo/">Link 1</a>` ;
229- var expected = ` <a href="//${ proxyUrl } /foo/">Link 1</a>` ;
177+ var input = ' <a href="http://example.com:1234/foo/">Link 1</a>' ;
178+ var expected = ' <a href="//' + proxyUrl + ' /foo/">Link 1</a>' ;
230179 var rewrite = utils . rewriteLinks ( { hostname : "example.com" , port : 1234 } , proxyUrl ) ;
231180 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
232181 var actual = input . replace ( rewrite . match , bound ) ;
233182 assert . equal ( actual , expected ) ;
234183 } ) ;
235184 it ( "should not greedy match when not inside attr - with paths" , function ( ) {
236- var input = ` <a href="https://example.com/calendar/2015/06/24/20471/">https://example.com/calendar/2015/06/24/20471/</a></p></div></li></ol></td><td class="cal-current-month">` ;
237- var expected = ` <a href="//${ proxyUrl } /calendar/2015/06/24/20471/">//${ proxyUrl } /calendar/2015/06/24/20471/</a></p></div></li></ol></td><td class="cal-current-month">` ;
185+ var input = ' <a href="https://example.com/calendar/2015/06/24/20471/">https://example.com/calendar/2015/06/24/20471/</a></p></div></li></ol></td><td class="cal-current-month">' ;
186+ var expected = ' <a href="//' + proxyUrl + ' /calendar/2015/06/24/20471/">//' + proxyUrl + ' /calendar/2015/06/24/20471/</a></p></div></li></ol></td><td class="cal-current-month">' ;
238187 var rewrite = utils . rewriteLinks ( { hostname : "example.com" } , proxyUrl ) ;
239188 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
240189 var actual = input . replace ( rewrite . match , bound ) ;
241190 assert . equal ( actual , expected ) ;
242191 } ) ;
243192 it ( "should not greedy match when not inside attr" , function ( ) {
244- var input = ` <a href="https://example.com/">https://example.com/</a></p></div></li></ol></td><td class="cal-current-month">` ;
245- var expected = ` <a href="//${ proxyUrl } /">//${ proxyUrl } /</a></p></div></li></ol></td><td class="cal-current-month">` ;
193+ var input = ' <a href="https://example.com/">https://example.com/</a></p></div></li></ol></td><td class="cal-current-month">' ;
194+ var expected = ' <a href="//192.168.0.4:3002 /">//192.168.0.4:3002 /</a></p></div></li></ol></td><td class="cal-current-month">' ;
246195 var rewrite = utils . rewriteLinks ( { hostname : "example.com" } , proxyUrl ) ;
247196 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
248197 var actual = input . replace ( rewrite . match , bound ) ;
249198 assert . equal ( actual , expected ) ;
250199 } ) ;
251200 it ( "handles escaped urls correctly" , function ( ) {
252- const input = fs . readFileSync ( "test/fixtures/escaped.1.html" , "utf8" ) ;
253- const expected = fs . readFileSync ( "test/fixtures/escaped.1.expected.html" , "utf8" ) ;
201+ var input = fs . readFileSync ( "test/fixtures/rewrites /escaped.1.html" , "utf8" ) ;
202+ var expected = fs . readFileSync ( "test/fixtures/rewrites /escaped.1.expected.html" , "utf8" ) ;
254203 var rewrite = utils . rewriteLinks ( { hostname : "demo.l5" } , proxyUrl ) ;
255204 var bound = rewrite . fn . bind ( null , { headers : { host : proxyUrl } } , { } ) ;
256205 var actual = input . replace ( rewrite . match , bound ) ;
0 commit comments