forked from YellowLabTools/YellowLabTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphantomasWrapperTest.js
85 lines (67 loc) · 2.6 KB
/
phantomasWrapperTest.js
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
74
75
76
77
78
79
80
81
82
83
84
85
var should = require('chai').should();
var phantomasWrapper = require('../../lib/tools/phantomas/phantomasWrapper');
describe('phantomasWrapper', function() {
it('should have a method execute', function() {
phantomasWrapper.should.have.property('execute').that.is.a('function');
});
it('should execute', function(done) {
var url = 'http://localhost:8388/simple-page.html';
this.timeout(15000);
phantomasWrapper.execute({
params: {
url: url,
options: {}
}
}).then(function(data) {
data.should.be.an('object');
data.should.have.a.property('generator');
data.generator.should.contain('phantomas');
data.should.have.a.property('url').that.equals(url);
data.should.have.a.property('metrics').that.is.an('object').not.empty();
data.should.have.a.property('offenders').that.is.an('object').not.empty();
data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty();
done();
}).fail(function(err) {
done(err);
});
});
it('should fail with error 254', function(done) {
var url = 'http://localhost:8389/not-existing.html';
this.timeout(15000);
phantomasWrapper.execute({
params: {
url: url,
options: {}
}
}).then(function(data) {
done('Error: unwanted success');
}).fail(function(err) {
should.exist(err);
err.should.equal(254);
done();
});
});
it('should timeout but return some results', function(done) {
var url = 'http://localhost:8388/simple-page.html';
this.timeout(5000);
phantomasWrapper.execute({
params: {
url: url,
options: {
timeout: 1
}
}
}).then(function(data) {
data.should.be.an('object');
data.should.have.a.property('generator');
data.generator.should.contain('phantomas');
data.should.have.a.property('url').that.equals(url);
data.should.have.a.property('metrics').that.is.an('object').not.empty();
data.should.have.a.property('offenders').that.is.an('object').not.empty();
data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty();
done();
}).fail(function(err) {
done(err);
});
});
});