phantomasWrapperTest.js 2.9 KB

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