phantomasWrapperTest.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var should = require('chai').should();
  2. var phantomasWrapper = require('../../lib/tools/phantomasWrapper');
  3. describe('phantomasWrapper', function() {
  4. it('should have a method execute', function() {
  5. phantomasWrapper.should.have.property('execute').that.is.a('function');
  6. });
  7. it('should execute', function(done) {
  8. var url = 'http://localhost:8388/simple-page.html';
  9. this.timeout(15000);
  10. phantomasWrapper.execute({
  11. url: url,
  12. options: {}
  13. }).then(function(json) {
  14. json.should.be.an('object');
  15. json.should.have.a.property('generator');
  16. json.generator.should.contain('phantomas');
  17. json.should.have.a.property('url').that.equals(url);
  18. json.should.have.a.property('metrics').that.is.an('object').not.empty;
  19. json.should.have.a.property('offenders').that.is.an('object').not.empty;
  20. json.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
  21. done();
  22. }).fail(function(err) {
  23. done(err);
  24. });
  25. });
  26. it('should fail with error 254', function(done) {
  27. var url = 'http://localhost:8389/not-existing.html';
  28. this.timeout(15000);
  29. phantomasWrapper.execute({
  30. url: url,
  31. options: {}
  32. }).then(function(json) {
  33. done('Error: unwanted success');
  34. }).fail(function(err) {
  35. should.exist(err);
  36. err.should.equal(254);
  37. done();
  38. });
  39. });
  40. it('should timeout but return some results', function(done) {
  41. var url = 'http://localhost:8388/simple-page.html';
  42. this.timeout(5000);
  43. phantomasWrapper.execute({
  44. url: url,
  45. options: {
  46. timeout: 1
  47. }
  48. }).then(function(json) {
  49. json.should.be.an('object');
  50. json.should.have.a.property('generator');
  51. json.generator.should.contain('phantomas');
  52. json.should.have.a.property('url').that.equals(url);
  53. json.should.have.a.property('metrics').that.is.an('object').not.empty;
  54. json.should.have.a.property('offenders').that.is.an('object').not.empty;
  55. json.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
  56. done();
  57. }).fail(function(err) {
  58. done(err);
  59. });
  60. });
  61. });