phantomasWrapperTest.js 2.6 KB

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