CLI is working, API not ready, Front broken

This commit is contained in:
Gaël Métais
2014-11-28 10:45:30 +01:00
parent b72e74e0d3
commit 1f83fe1b48
20 changed files with 1001 additions and 94 deletions
+78
View File
@@ -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);
});
});
});
+30
View File
@@ -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);
});
});
});
+52
View File
@@ -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);
});
});
});