phantomasWrapperTest.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. done();
  24. }).fail(function(err) {
  25. done(err);
  26. });
  27. });
  28. it('should fail when page cannot be fetched', function(done) {
  29. var url = 'http://localhost:8389/not-existing.html';
  30. this.timeout(15000);
  31. phantomasWrapper.execute({
  32. params: {
  33. url: url,
  34. options: {
  35. device: 'desktop'
  36. }
  37. }
  38. }).then(function(data) {
  39. done('Error: unwanted success');
  40. }).fail(function(err) {
  41. try {
  42. console.log(err);
  43. should.exist(err);
  44. done();
  45. } catch(error) {
  46. done(error);
  47. }
  48. });
  49. });
  50. });