@@ -4,6 +4,7 @@ const should = require('should');
44const sinon = require ( 'sinon' ) ;
55const Promise = require ( 'bluebird' ) ;
66const proxyquire = require ( 'proxyquire' ) ;
7+ const path = require ( 'path' ) ;
78const Resource = require ( '../../../lib/resource' ) ;
89const ResourceHandler = require ( '../../../lib/resource-handler' ) ;
910
@@ -182,19 +183,21 @@ describe('ResourceHandler', function() {
182183 pathContainer . getPaths . returns ( [
183184 'http://first.com/img/a.jpg' ,
184185 'http://first.com/b.jpg' ,
185- 'http://second.com/img/c.jpg'
186+ 'http://second.com/img/c.jpg' ,
187+ 'http://second.com/d' ,
186188 ] ) ;
187189
188- scraperContext . requestResource . onFirstCall ( ) . returns ( Promise . resolve ( new Resource ( 'http://first.com/img/a.jpg' , 'local/a.jpg' ) ) ) ;
189- scraperContext . requestResource . onSecondCall ( ) . returns ( Promise . resolve ( new Resource ( 'http://first.com/b.jpg' , 'local/b.jpg' ) ) ) ;
190- scraperContext . requestResource . onThirdCall ( ) . returns ( Promise . resolve ( new Resource ( 'http://second.com/img/c.jpg' , 'local/c.jpg' ) ) ) ;
190+ scraperContext . requestResource . onCall ( 0 ) . returns ( Promise . resolve ( new Resource ( 'http://first.com/img/a.jpg' , 'local' + path . sep + 'a.jpg' ) ) ) ;
191+ scraperContext . requestResource . onCall ( 1 ) . returns ( Promise . resolve ( new Resource ( 'http://first.com/b.jpg' , 'local' + path . sep + 'b.jpg' ) ) ) ;
192+ scraperContext . requestResource . onCall ( 2 ) . returns ( Promise . resolve ( new Resource ( 'http://second.com/img/c.jpg' , 'local' + path . sep + 'c.jpg' ) ) ) ;
193+ scraperContext . requestResource . onCall ( 3 ) . returns ( Promise . resolve ( new Resource ( 'http://second.com/d' , 'a%b' + path . sep + '"\'( )?p=q&\\#' ) ) ) ;
191194
192195 var updateChildSpy = sinon . spy ( parentResource , 'updateChild' ) ;
193196
194197 return resHandler . downloadChildrenResources ( pathContainer , parentResource ) . then ( function ( ) {
195198 var updateTextStub = pathContainer . updateText ;
196199 updateTextStub . calledOnce . should . be . eql ( true ) ;
197- updateTextStub . args [ 0 ] [ 0 ] . length . should . be . eql ( 3 ) ;
200+ updateTextStub . args [ 0 ] [ 0 ] . length . should . be . eql ( 4 ) ;
198201 updateTextStub . args [ 0 ] [ 0 ] . should . containEql ( {
199202 oldPath : 'http://first.com/img/a.jpg' ,
200203 newPath : 'local/a.jpg'
@@ -207,7 +210,11 @@ describe('ResourceHandler', function() {
207210 oldPath : 'http://second.com/img/c.jpg' ,
208211 newPath : 'local/c.jpg'
209212 } ) ;
210- updateChildSpy . calledThrice . should . be . eql ( true ) ;
213+ updateTextStub . args [ 0 ] [ 0 ] . should . containEql ( {
214+ oldPath : 'http://second.com/d' ,
215+ newPath : 'a%25b/%22%27%28%20%29%3Fp%3Dq%26' + ( path . sep === '\\' ? '/' : '%5C' ) + '%23'
216+ } ) ;
217+ updateChildSpy . callCount . should . be . eql ( 4 ) ;
211218 } ) ;
212219 } ) ;
213220
0 commit comments