phantomasWrapperTest.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. device: 'desktop'
  37. }
  38. }
  39. }).then(function(data) {
  40. console.log(data);
  41. done('Error: unwanted success');
  42. }).fail(function(err) {
  43. should.exist(err);
  44. err.should.equal(254);
  45. done();
  46. });
  47. });
  48. it('should timeout but return some results', function(done) {
  49. var url = 'http://localhost:8388/simple-page.html';
  50. this.timeout(5000);
  51. phantomasWrapper.execute({
  52. params: {
  53. url: url,
  54. options: {
  55. timeout: 1
  56. }
  57. }
  58. }).then(function(data) {
  59. /*jshint -W030 */
  60. data.should.be.an('object');
  61. data.should.have.a.property('generator');
  62. data.generator.should.contain('phantomas');
  63. data.should.have.a.property('url').that.equals(url);
  64. data.should.have.a.property('metrics').that.is.an('object').not.empty;
  65. data.should.have.a.property('offenders').that.is.an('object').not.empty;
  66. data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty;
  67. done();
  68. }).fail(function(err) {
  69. done(err);
  70. });
  71. });
  72. });