examples.test.js
1.58 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*jshint expr:true */
'use strict';
var Crawler = require('../lib/crawler');
var expect = require('chai').expect;
var sinon = require('sinon');
var nock = require('nock');
var c, spy;
describe('Simple test', function () {
before(function() {
nock.cleanAll();
});
beforeEach(function () {
nock('http://nockhost').get(uri => uri.indexOf('status') >= 0).times(20).reply(200, 'Yes');
c = new Crawler({ maxConnections: 10, jquery: false });
});
afterEach(function () {
c = {};
spy = {};
});
it('should run the first readme examples', function (done) {
// Access to Github might be slow
this.timeout(6000);
c.queue({
uri: 'http://github.com',
callback: function (err, result, done) {
expect(err).to.be.null;
expect(typeof result.body).to.equal('string');
done();
}
});
c.on('drain', done);
});
it('should run the readme examples', function (done) {
c = new Crawler({
maxConnections: 10,
jquery: false,
callback: function (err, result, done) {
expect(err).to.be.null;
done();
}
});
c.on('drain', function () {
expect(spy.calledTwice).to.be.true;
done();
});
spy = sinon.spy(c, 'queue');
c.queue('http://nockhost/status/200');
c.queue('http://nockhost/status/200');
});
it('should run the with an array queue', function (done) {
this.timeout(6000);
c.queue([{
uri: 'http://www.github.com',
jquery: true,
callback: function (err, result, done) {
expect(err).to.be.null;
expect(result.$).not.to.be.null;
expect(typeof result.body).to.equal('string');
done();
}
}]);
c.on('drain', done);
});
});