API is starting to run
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
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({
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
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() {
|
||||
var data = require('../fixtures/rulesCheckerInput.json');
|
||||
var policies = require('../fixtures/rulesCheckerPolicies.json');
|
||||
var expected = require('../fixtures/rulesCheckerOutput.json');
|
||||
|
||||
var results = rulesChecker.check(data, policies);
|
||||
results.should.deep.equals(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
var chai = require('chai');
|
||||
var sinon = require('sinon');
|
||||
var sinonChai = require('sinon-chai');
|
||||
var should = chai.should();
|
||||
var YellowLabTools = require('../../lib/yellowlabtools.js');
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
// Check if console.log is called
|
||||
sinon.spy(console, 'log');
|
||||
|
||||
var url = 'http://localhost:8388/simple-page.html';
|
||||
|
||||
var ylt = new YellowLabTools(url)
|
||||
.then(function(data) {
|
||||
|
||||
data.should.be.an('object');
|
||||
data.toolsResults.should.be.an('object');
|
||||
|
||||
// Test Phantomas
|
||||
data.toolsResults.phantomas.should.be.an('object');
|
||||
data.toolsResults.phantomas.should.have.a.property('url').that.equals(url);
|
||||
data.toolsResults.phantomas.should.have.a.property('metrics').that.is.an('object');
|
||||
data.toolsResults.phantomas.metrics.should.have.a.property('requests').that.equals(1);
|
||||
data.toolsResults.phantomas.should.have.a.property('offenders').that.is.an('object');
|
||||
data.toolsResults.phantomas.offenders.should.have.a.property('DOMelementMaxDepth');
|
||||
data.toolsResults.phantomas.offenders.DOMelementMaxDepth.should.have.length(1);
|
||||
data.toolsResults.phantomas.offenders.DOMelementMaxDepth[0].should.equal('body > h1[1]');
|
||||
|
||||
// Test rules
|
||||
data.should.have.a.property('rules').that.is.an('object');
|
||||
|
||||
data.rules.should.have.a.property('DOMelementMaxDepth').that.is.an('object');
|
||||
data.rules.DOMelementMaxDepth.should.deep.equal({
|
||||
policy: {
|
||||
"tool": "phantomas",
|
||||
"label": "DOM max depth",
|
||||
"message": "<p>A deep DOM makes the CSS matching with DOM elements difficult.</p><p>It also slows down Javascript modifications to the DOM because changing the dimensions of an element makes the browser re-calculate the dimensions of it's parents. Same thing for Javascript events, that bubble up to the document root.</p>",
|
||||
"isOkThreshold": 10,
|
||||
"isBadThreshold": 20,
|
||||
"isAbnormalThreshold": 30
|
||||
},
|
||||
"value": 1,
|
||||
"bad": false,
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
"abnormalityScore": 0,
|
||||
"offenders": ["body > h1[1]"]
|
||||
});
|
||||
|
||||
/*jshint expr: true*/
|
||||
console.log.should.not.have.been.called;
|
||||
|
||||
done();
|
||||
}).fail(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user