yellowlabtoolsTest.js 3.2 KB

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