From 63a5169d21610418a0d5bfa185234742bb45d047 Mon Sep 17 00:00:00 2001 From: s0ph1e Date: Wed, 2 Sep 2020 20:59:02 +0300 Subject: [PATCH] Add test for same resource with different depth --- test/functional/max-depth/max-depth.test.js | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/functional/max-depth/max-depth.test.js b/test/functional/max-depth/max-depth.test.js index ae0792bf..2306f614 100644 --- a/test/functional/max-depth/max-depth.test.js +++ b/test/functional/max-depth/max-depth.test.js @@ -110,4 +110,52 @@ describe('Functional: maxDepth and maxRecursiveDepth ', () => { }); }); + it('should correctly save same resource with different depth and maxRecursiveDepth', () => { + /* + pageA -> pageB + pageA -> pageC + pageB -> pageC + * */ + const options = { + urls: [ {url: 'http://example.com/pageA.html', filename: 'pageA.html'} ], + directory: testDirname, + subdirectories: null, + sources: [ + { selector: 'a', attr: 'href' } + ], + maxRecursiveDepth: 1 + }; + + const pageA = ` + + + + + `; + + const pageB = ` + + + + `; + + nock('http://example.com/').get('/pageA.html').reply(200, pageA, {'Content-Type': 'text/html'}); + nock('http://example.com/').get('/pageB.html').reply(200, pageB, {'Content-Type': 'text/html'}); + nock('http://example.com/').get('/pageC.html').reply(200, 'pageC', {'Content-Type': 'text/html'}); + + return scrape(options).then(() => { + fs.existsSync(testDirname + '/pageA.html').should.be.eql(true); + fs.existsSync(testDirname + '/pageB.html').should.be.eql(true); + fs.existsSync(testDirname + '/pageC.html').should.be.eql(true); + + const pageASaved = fs.readFileSync(testDirname + '/pageA.html').toString(); + pageASaved.should.containEql(' maxRecursiveDepth + }); + }); + });