phantomasWrapperTest.js 2.7 KB

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