phantomasWrapperTest.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. params: {
  12. url: url,
  13. options: {}
  14. }
  15. }).then(function(data) {
  16. data.should.be.an('object');
  17. data.should.have.a.property('generator');
  18. data.generator.should.contain('phantomas');
  19. data.should.have.a.property('url').that.equals(url);
  20. data.should.have.a.property('metrics').that.is.an('object').not.empty;
  21. data.should.have.a.property('offenders').that.is.an('object').not.empty;
  22. data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
  23. done();
  24. }).fail(function(err) {
  25. done(err);
  26. });
  27. });
  28. it('should fail with error 254', function(done) {
  29. var url = 'http://localhost:8389/not-existing.html';
  30. this.timeout(15000);
  31. phantomasWrapper.execute({
  32. params: {
  33. url: url,
  34. options: {}
  35. }
  36. }).then(function(data) {
  37. done('Error: unwanted success');
  38. }).fail(function(err) {
  39. should.exist(err);
  40. err.should.equal(254);
  41. done();
  42. });
  43. });
  44. it('should timeout but return some results', function(done) {
  45. var url = 'http://localhost:8388/simple-page.html';
  46. this.timeout(5000);
  47. phantomasWrapper.execute({
  48. params: {
  49. url: url,
  50. options: {
  51. timeout: 1
  52. }
  53. }
  54. }).then(function(data) {
  55. data.should.be.an('object');
  56. data.should.have.a.property('generator');
  57. data.generator.should.contain('phantomas');
  58. data.should.have.a.property('url').that.equals(url);
  59. data.should.have.a.property('metrics').that.is.an('object').not.empty;
  60. data.should.have.a.property('offenders').that.is.an('object').not.empty;
  61. data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
  62. done();
  63. }).fail(function(err) {
  64. done(err);
  65. });
  66. });
  67. });