yellowlabtoolsTest.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var chai = require('chai');
  2. var sinon = require('sinon');
  3. var sinonChai = require('sinon-chai');
  4. var should = chai.should();
  5. var YellowLabTools = require('../../lib/yellowlabtools.js');
  6. chai.use(sinonChai);
  7. describe('yellowlabtools', function() {
  8. it('returns a promise', function() {
  9. var ylt = new YellowLabTools();
  10. ylt.should.have.property('then').that.is.a('function');
  11. ylt.should.have.property('fail').that.is.a('function');
  12. });
  13. it('fails an undefined url', function(done) {
  14. var ylt = new YellowLabTools().fail(function(err) {
  15. err.should.be.a('string').that.equals('URL missing');
  16. done();
  17. });
  18. });
  19. it('fails with an empty url string', function(done) {
  20. var ylt = new YellowLabTools('').fail(function(err) {
  21. err.should.be.a('string').that.equals('URL missing');
  22. done();
  23. });
  24. });
  25. it('succeeds on simple-page.html', function(done) {
  26. this.timeout(15000);
  27. // Check if console.log is called
  28. sinon.spy(console, 'log')
  29. var url = 'http://localhost:8388/simple-page.html';
  30. var ylt = new YellowLabTools(url)
  31. .then(function(data) {
  32. data.should.be.an('object');
  33. data.toolsResults.should.be.an('object');
  34. // Test Phantomas
  35. data.toolsResults.phantomas.should.be.an('object');
  36. data.toolsResults.phantomas.should.have.a.property('url').that.equals(url);
  37. data.toolsResults.phantomas.should.have.a.property('metrics').that.is.an('object');
  38. data.toolsResults.phantomas.metrics.should.have.a.property('requests').that.equals(1);
  39. data.toolsResults.phantomas.should.have.a.property('offenders').that.is.an('object');
  40. data.toolsResults.phantomas.offenders.should.have.a.property('DOMelementMaxDepth');
  41. data.toolsResults.phantomas.offenders.DOMelementMaxDepth.should.have.length(1);
  42. data.toolsResults.phantomas.offenders.DOMelementMaxDepth[0].should.equal('body > h1[1]');
  43. // Test rules
  44. data.should.have.a.property('rules').that.is.an('object');
  45. data.rules.should.have.a.property('DOMelementMaxDepth').that.is.an('object');
  46. data.rules.DOMelementMaxDepth.should.deep.equal({
  47. policy: {
  48. "tool": "phantomas",
  49. "label": "DOM max depth",
  50. "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>",
  51. "isOkThreshold": 10,
  52. "isBadThreshold": 20,
  53. "isAbnormalThreshold": 30
  54. },
  55. "value": 1,
  56. "bad": false,
  57. "abnormal": false,
  58. "score": 100,
  59. "abnormalityScore": 0,
  60. "offenders": ["body > h1[1]"]
  61. });
  62. console.log.should.not.have.been.called;
  63. done();
  64. }).fail(function(err) {
  65. done(err);
  66. });
  67. });
  68. });