phantomasWrapperTest.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. });