forked from ruipgil/scraperjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractScraper.js
More file actions
73 lines (71 loc) · 1.84 KB
/
AbstractScraper.js
File metadata and controls
73 lines (71 loc) · 1.84 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
/* global describe, it */
var AbstractScraper = require('../src/AbstractScraper'),
fs = require('fs'),
assert = require('assert'),
MISSING = 'http://0.0.0.0',
HN_CLONE = 'http://localhost:3000/hacker-news-clone';
describe('AbstractScraper', function() {
it('get', function(done) {
var as = new AbstractScraper();
as.get(MISSING, function(err) {
assert.ok((err.code == 'EADDRNOTAVAIL') || (err.code == 'ECONNREFUSED'));
done();
});
});
it('request', function(done) {
var as = new AbstractScraper();
as.request({
url: MISSING
}, function(err) {
assert.ok((err.code == 'EADDRNOTAVAIL') || (err.code == 'ECONNREFUSED'));
done();
});
});
it('getStatusCode', function(done) {
var as = new AbstractScraper();
as.get(HN_CLONE, function(err) {
assert.ok(!err);
assert.equal(as.getStatusCode(), 200);
done();
});
});
it('getResponse', function(done) {
var as = new AbstractScraper();
as.get(HN_CLONE, function(err) {
assert.ok(!err);
assert.ok(!!as.getResponse());
assert.equal(as.getResponse().statusCode, 200);
done();
});
});
it('getBody', function(done) {
var as = new AbstractScraper();
as.get(HN_CLONE, function(err) {
assert.ok(!err);
assert.equal(as.getBody(), fs.readFileSync(__dirname + '/static/hacker-news-clone.html').toString());
done();
});
});
it('loadBody', function(done) {
var as = new AbstractScraper();
as.loadBody(function() {
done();
});
});
it('scrape', function() {
var as = new AbstractScraper();
as.scrape(function() {
assert.fail('Function shouldn\'t be called');
}, function() {
assert.fail('Function shouldn\'t be called');
});
});
it('close', function() {
var as = new AbstractScraper();
assert.ok(as.close() === undefined);
});
it('clone', function() {
var as = new AbstractScraper();
assert.ok(as.clone() === undefined);
});
});