Implements a general score calculator

This commit is contained in:
Gaël Métais
2014-12-14 15:47:58 +01:00
parent 8abfe93df7
commit 792f7d8e21
11 changed files with 478 additions and 20 deletions
+18
View File
@@ -0,0 +1,18 @@
var should = require('chai').should();
var scoreCalculator = require('../../lib/scoreCalculator');
describe('scoreCalculator', function() {
it('should have a method calculate', function() {
scoreCalculator.should.have.property('calculate').that.is.a('function');
});
it('should produce a nice rules object', function() {
var data = require('../fixtures/scoreInput.json');
var profile = require('../fixtures/scoreProfile.json');
var expected = require('../fixtures/scoreOutput.json');
var results = scoreCalculator.calculate(data, profile);
results.should.deep.equals(expected);
});
});
+11 -4
View File
@@ -9,28 +9,28 @@ chai.use(sinonChai);
describe('yellowlabtools', function() {
it('returns a promise', function() {
it('should return 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) {
it('should fail 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) {
it('should fail 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) {
it('should succeeds on simple-page.html', function(done) {
this.timeout(15000);
// Check if console.log is called
@@ -75,6 +75,13 @@ describe('yellowlabtools', function() {
"offenders": ["body > h1[1]"]
});
// Test javascriptExecutionTree
data.toolsResults.phantomas.metrics.should.not.have.a.property('javascriptExecutionTree');
data.toolsResults.phantomas.offenders.should.not.have.a.property('javascriptExecutionTree');
data.should.have.a.property('javascriptExecutionTree').that.is.an('object');
data.javascriptExecutionTree.should.have.a.property('data');
data.javascriptExecutionTree.data.should.have.a.property('type').that.equals('main');
/*jshint expr: true*/
console.log.should.not.have.been.called;