|
| 1 | +require('should'); |
| 2 | +var nock = require('nock'); |
| 3 | +var fs = require('fs-extra'); |
| 4 | +var path = require('path'); |
| 5 | +var _ = require('underscore'); |
| 6 | +var scraper = require('../../index'); |
| 7 | + |
| 8 | +var testDirname = __dirname + '/.recursive'; |
| 9 | +var mockDirname = __dirname + '/mocks/recursive'; |
| 10 | + |
| 11 | +describe('Functional recursive downloading', function() { |
| 12 | + |
| 13 | + beforeEach(function() { |
| 14 | + nock.cleanAll(); |
| 15 | + nock.disableNetConnect(); |
| 16 | + }); |
| 17 | + |
| 18 | + afterEach(function() { |
| 19 | + nock.cleanAll(); |
| 20 | + nock.enableNetConnect(); |
| 21 | + fs.removeSync(testDirname); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should follow anchors', function(done) { |
| 25 | + var options = { |
| 26 | + urls: [ 'http://example.com/' ], |
| 27 | + directory: testDirname, |
| 28 | + subdirectories: null, |
| 29 | + sources: [], |
| 30 | + recursive: true |
| 31 | + }; |
| 32 | + |
| 33 | + nock('http://example.com/').get('/').replyWithFile(200, mockDirname + '/index.html'); |
| 34 | + |
| 35 | + // mock for anchors |
| 36 | + nock('http://example.com/').get('/about.html').replyWithFile(200, mockDirname + '/about.html'); |
| 37 | + nock('http://example.com/').get('/link1.html').reply(200, 'content 1'); |
| 38 | + nock('http://example.com/').get('/link2.html').reply(200, 'content 2'); |
| 39 | + nock('http://example.com/').get('/link3.html').reply(200, 'content 3'); |
| 40 | + |
| 41 | + scraper.scrape(options).then(function() { |
| 42 | + fs.existsSync(testDirname + '/index.html').should.be.eql(true); |
| 43 | + |
| 44 | + // index.html anchors loaded |
| 45 | + fs.existsSync(testDirname + '/about.html').should.be.eql(true); |
| 46 | + |
| 47 | + // about.html anchors loaded |
| 48 | + fs.existsSync(testDirname + '/link1.html').should.be.eql(true); |
| 49 | + fs.existsSync(testDirname + '/link2.html').should.be.eql(true); |
| 50 | + fs.existsSync(testDirname + '/link3.html').should.be.eql(true); |
| 51 | + |
| 52 | + done(); |
| 53 | + }).catch(done); |
| 54 | + }); |
| 55 | +}); |
0 commit comments