UNPKG

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