@@ -110,4 +110,52 @@ describe('Functional: maxDepth and maxRecursiveDepth ', () => {
110110 } ) ;
111111 } ) ;
112112
113+ it ( 'should correctly save same resource with different depth and maxRecursiveDepth' , ( ) => {
114+ /*
115+ pageA -> pageB
116+ pageA -> pageC
117+ pageB -> pageC
118+ * */
119+ const options = {
120+ urls : [ { url : 'http://example.com/pageA.html' , filename : 'pageA.html' } ] ,
121+ directory : testDirname ,
122+ subdirectories : null ,
123+ sources : [
124+ { selector : 'a' , attr : 'href' }
125+ ] ,
126+ maxRecursiveDepth : 1
127+ } ;
128+
129+ const pageA = `<html>
130+ <body>
131+ <a href="/pageB.html"></a>
132+ <a href="/pageC.html"></a>
133+ </body>
134+ </html>` ;
135+
136+ const pageB = `<html>
137+ <body>
138+ <a href="/pageC.html"></a>
139+ </body>
140+ </html>` ;
141+
142+ nock ( 'http://example.com/' ) . get ( '/pageA.html' ) . reply ( 200 , pageA , { 'Content-Type' : 'text/html' } ) ;
143+ nock ( 'http://example.com/' ) . get ( '/pageB.html' ) . reply ( 200 , pageB , { 'Content-Type' : 'text/html' } ) ;
144+ nock ( 'http://example.com/' ) . get ( '/pageC.html' ) . reply ( 200 , 'pageC' , { 'Content-Type' : 'text/html' } ) ;
145+
146+ return scrape ( options ) . then ( ( ) => {
147+ fs . existsSync ( testDirname + '/pageA.html' ) . should . be . eql ( true ) ;
148+ fs . existsSync ( testDirname + '/pageB.html' ) . should . be . eql ( true ) ;
149+ fs . existsSync ( testDirname + '/pageC.html' ) . should . be . eql ( true ) ;
150+
151+ const pageASaved = fs . readFileSync ( testDirname + '/pageA.html' ) . toString ( ) ;
152+ pageASaved . should . containEql ( '<a href="pageB.html"' ) ;
153+ pageASaved . should . containEql ( '<a href="pageC.html"' ) ;
154+
155+ const pageBSaved = fs . readFileSync ( testDirname + '/pageB.html' ) . toString ( ) ;
156+ // todo: should we change reference here because pageC was already downloaded?
157+ pageBSaved . should . containEql ( '<a href="/pageC.html"' ) ; // reference to pageC was not changed here because it > maxRecursiveDepth
158+ } ) ;
159+ } ) ;
160+
113161} ) ;
0 commit comments