1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- var chai = require('chai');
- var sinon = require('sinon');
- var sinonChai = require('sinon-chai');
- var should = chai.should();
- var ylt = require('../../lib/index');
- chai.use(sinonChai);
- describe('index.js', function() {
- it('should return a promise', function() {
- var promise = ylt();
- promise.should.have.property('then').that.is.a('function');
- promise.should.have.property('fail').that.is.a('function');
- });
- it('should fail an undefined url', function(done) {
- ylt().fail(function(err) {
- err.should.be.a('string').that.equals('URL missing');
- done();
- });
- });
- it('should fail with an empty url string', function(done) {
- ylt('').fail(function(err) {
- err.should.be.a('string').that.equals('URL missing');
- done();
- });
- });
- it('should succeed 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';
- ylt(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": 28
- },
- "value": 1,
- "bad": false,
- "abnormal": false,
- "score": 100,
- "abnormalityScore": 0,
- "offenders": "<div class=\"domTree\"><div><span>body</span><div><span>h1[1]</span></div></div></div>",
- "offendersCount": 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;
- done();
- }).fail(function(err) {
- done(err);
- });
- });
- });
|