uriOption.test.js
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*jshint expr:true */
'use strict';
const Crawler = require('../lib/crawler');
const expect = require('chai').expect;
const sinon = require('sinon');
// settings for nock to mock http server
const nock = require('nock');
describe('Uri Options', function() {
before(function() {
nock.cleanAll();
nock('http://test.crawler.com').get('/').reply(200, 'ok').persist();
});
const crawler = new Crawler({ jQuery: false });
it('should work if uri is string', function(finishTest) {
crawler.queue({
uri: 'http://test.crawler.com/',
callback: (error, response, done) => {
expect(error).to.be.null;
done();
finishTest();
}
});
});
it('should work if uri is a function', function(finishTest) {
function uriFn(onUri) {
onUri('http://test.crawler.com/');
}
crawler.queue({
uri: uriFn,
callback: (error, response, done) => {
expect(error).to.be.null;
done();
finishTest();
}
});
});
it('should skip if the uri is undefined or an empty string', function(finishTest) {
const push = sinon.spy(crawler, '_pushToQueue');
crawler.queue([undefined, null, []]);
crawler.queue({
uri: 'http://test.crawler.com/',
callback: (error, response, done) => {
expect(push.calledOnce).to.be.true;
done();
finishTest();
}
});
});
});