reporter-html.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function HtmlReporter(options, callback){
  2. console.debug('Creating HtmlReporter');
  3. this.format = 'html';
  4. this._report = '';
  5. this._window = {};
  6. var jasmine = options.jasminePath,
  7. jasmineHtml = options.jasmineHtmlPath,
  8. skeleton = options.skeletonPath,
  9. that = this;
  10. console.debug('Constructing HtmlReporter DOM');
  11. require('jsdom').env({
  12. html: skeleton,
  13. scripts: [ jasmine, jasmineHtml ],
  14. done: function(errors,window){
  15. if(errors) console.error('Error construction DOM for html reporter: ',errors);
  16. console.debug('Creating TrivialReporter instance.');
  17. var trivialReporter = new window.jasmine.TrivialReporter();
  18. console.debug('Transferring TrivialReporter methods to HtmlReporter object');
  19. for(var k in trivialReporter) that[k] = trivialReporter[k];
  20. that._window = window;
  21. console.debug('Done creating HtmlReporter');
  22. callback(that);
  23. }
  24. });
  25. };
  26. HtmlReporter.prototype.updateReport = function(){
  27. this._report = this._window.document.outerHTML;
  28. };
  29. HtmlReporter.prototype.getReport = function(){
  30. return this._report;
  31. };
  32. HtmlReporter.prototype.reset = function(){
  33. this._window.document.body.innerHTML = ''; // clear for next report
  34. };
  35. exports.create = function(options,callback){
  36. return new HtmlReporter(options,callback);
  37. };