CLI is working, API not ready, Front broken
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
var should = require('chai').should();
|
||||
var phantomasWrapper = require('../../lib/tools/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({
|
||||
url: url,
|
||||
options: {}
|
||||
}).then(function(json) {
|
||||
json.should.be.an('object');
|
||||
json.should.have.a.property('generator');
|
||||
json.generator.should.contain('phantomas');
|
||||
json.should.have.a.property('url').that.equals(url);
|
||||
json.should.have.a.property('metrics').that.is.an('object').not.empty;
|
||||
json.should.have.a.property('offenders').that.is.an('object').not.empty;
|
||||
json.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({
|
||||
url: url,
|
||||
options: {}
|
||||
}).then(function(json) {
|
||||
|
||||
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({
|
||||
url: url,
|
||||
options: {
|
||||
timeout: 1
|
||||
}
|
||||
}).then(function(json) {
|
||||
|
||||
json.should.be.an('object');
|
||||
json.should.have.a.property('generator');
|
||||
json.generator.should.contain('phantomas');
|
||||
json.should.have.a.property('url').that.equals(url);
|
||||
json.should.have.a.property('metrics').that.is.an('object').not.empty;
|
||||
json.should.have.a.property('offenders').that.is.an('object').not.empty;
|
||||
json.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
|
||||
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
var should = require('chai').should();
|
||||
var rulesChecker = require('../../lib/rulesChecker');
|
||||
|
||||
describe('rulesChecker', function() {
|
||||
|
||||
it('should have a method check', function() {
|
||||
rulesChecker.should.have.property('check').that.is.a('function');
|
||||
});
|
||||
|
||||
it('should produce a nice rules object', function(done) {
|
||||
var data = require('../fixtures/rulesCheckerInput.json');
|
||||
var policies = require('../fixtures/rulesCheckerPolicies.json');
|
||||
var expected = require('../fixtures/rulesCheckerOutput.json');
|
||||
|
||||
var checker = rulesChecker.check(data, policies);
|
||||
|
||||
checker.then(function(results) {
|
||||
try {
|
||||
results.should.deep.equals(expected);
|
||||
done();
|
||||
} catch(e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
|
||||
checker.fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
var should = require('chai').should();
|
||||
var YellowLabTools = require('../../lib/yellowlabtools.js');
|
||||
|
||||
|
||||
describe('yellowlabtools', function() {
|
||||
|
||||
it('returns a promise', function() {
|
||||
var ylt = new YellowLabTools();
|
||||
|
||||
ylt.should.have.property('then').that.is.a('function');
|
||||
ylt.should.have.property('fail').that.is.a('function');
|
||||
});
|
||||
|
||||
it('fails an undefined url', function(done) {
|
||||
var ylt = new YellowLabTools().fail(function(err) {
|
||||
err.should.be.a('string').that.equals('URL missing');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('fails with an empty url string', function(done) {
|
||||
var ylt = new YellowLabTools('').fail(function(err) {
|
||||
err.should.be.a('string').that.equals('URL missing');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('succeeds on simple-page.html', function(done) {
|
||||
this.timeout(15000);
|
||||
|
||||
var url = 'http://localhost:8388/simple-page.html';
|
||||
|
||||
var ylt = new YellowLabTools(url)
|
||||
.then(function(data) {
|
||||
data.should.be.an('object');
|
||||
data.should.have.a.property('url').that.equals(url);
|
||||
|
||||
data.should.have.a.property('metrics').that.is.an('object');
|
||||
data.metrics.should.have.a.property('requests').that.equals(1);
|
||||
|
||||
data.should.have.a.property('offenders').that.is.an('object');
|
||||
data.offenders.should.have.a.property('DOMelementMaxDepth');
|
||||
data.offenders.DOMelementMaxDepth.should.have.length(1);
|
||||
data.offenders.DOMelementMaxDepth[0].should.equal('body > h1[1]');
|
||||
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"tool1": {
|
||||
"metrics": {
|
||||
"metric1": 1236,
|
||||
"metric2": 222,
|
||||
"metric3": 6666,
|
||||
"metric4": 1000,
|
||||
"metric5": 3000,
|
||||
"metric6": 0,
|
||||
"metric7": 5000
|
||||
},
|
||||
"offenders": {
|
||||
"metric1": [],
|
||||
"metric2": [],
|
||||
"metric3": ["offender1", "offender2"],
|
||||
"metric5": []
|
||||
}
|
||||
},
|
||||
"tool2": {
|
||||
"metrics": {
|
||||
"metric1": 22,
|
||||
"metric10": 22
|
||||
}
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"metric1": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 1",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 1236,
|
||||
"bad": true,
|
||||
"abnormal": false,
|
||||
"score": 88,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
"metric2": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 2",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 222,
|
||||
"bad": false,
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
"metric3": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 3",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 6666,
|
||||
"offenders": ["offender1", "offender2"],
|
||||
"bad": true,
|
||||
"abnormal": true,
|
||||
"score": 0,
|
||||
"abnormalityScore": -42
|
||||
},
|
||||
"metric4": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 4",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 1000,
|
||||
"bad": false,
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
"metric5": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 5",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 3000,
|
||||
"bad": true,
|
||||
"abnormal": false,
|
||||
"score": 0,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
"metric6": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 6",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 0,
|
||||
"bad": false,
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
"metric7": {
|
||||
"policy": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 7",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 5000,
|
||||
"bad": true,
|
||||
"abnormal": true,
|
||||
"score": 0,
|
||||
"abnormalityScore": 0
|
||||
},
|
||||
|
||||
"metric10": {
|
||||
"policy": {
|
||||
"tool": "tool2",
|
||||
"label": "The metric 10",
|
||||
"message": "<p>This is from another tool!</p>",
|
||||
"isOkThreshold": 0,
|
||||
"isBadThreshold": 3,
|
||||
"isAbnormalThreshold": 11
|
||||
},
|
||||
"value": 22,
|
||||
"bad": true,
|
||||
"abnormal": true,
|
||||
"score": 0,
|
||||
"abnormalityScore": -100
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"metric1": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 1",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric2": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 2",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric3": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 3",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric4": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 4",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric5": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 5",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric6": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 6",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"metric7": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 7",
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
|
||||
"metric10": {
|
||||
"tool": "tool2",
|
||||
"label": "The metric 10",
|
||||
"message": "<p>This is from another tool!</p>",
|
||||
"isOkThreshold": 0,
|
||||
"isBadThreshold": 3,
|
||||
"isAbnormalThreshold": 11
|
||||
},
|
||||
|
||||
"unexistantMetric": {
|
||||
"tool": "tool1",
|
||||
"label": "",
|
||||
"message": "",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"unexistantTool": {
|
||||
"tool": "unexistant",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
var should = require('chai').should();
|
||||
var phantomasWrapper = require('../../app/lib/phantomasWrapper.js');
|
||||
|
||||
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://www.google.fr/';
|
||||
|
||||
this.timeout(20000);
|
||||
phantomasWrapper.execute({
|
||||
url: url,
|
||||
testId: '123abc',
|
||||
options:{
|
||||
|
||||
}
|
||||
}, function(err, json, results) {
|
||||
should.not.exist(err);
|
||||
|
||||
json.should.be.an('object');
|
||||
json.should.have.a.property('generator');
|
||||
json.generator.should.contain('phantomas');
|
||||
json.should.have.a.property('url').that.equals(url);
|
||||
json.should.have.a.property('metrics').that.is.an('object').not.empty;
|
||||
json.should.have.a.property('offenders').that.is.an('object').not.empty;
|
||||
json.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail with error 254', function(done) {
|
||||
var url = 'http://www.not.existing';
|
||||
|
||||
this.timeout(15000);
|
||||
phantomasWrapper.execute({
|
||||
url: url,
|
||||
testId: '123abc',
|
||||
options:{
|
||||
|
||||
}
|
||||
}, function(err, json, results) {
|
||||
should.exist(err);
|
||||
err.should.equal(254);
|
||||
should.not.exist(json);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Simple page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Simple page</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user