Code coverage report for lib/reporters/fail-reporter.js

Statements: 100% (24 / 24)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (24 / 24)      Ignored: none     

All files » lib/reporters/ » fail-reporter.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95    1 1                     1         3         3               1             1         1         1             1   2 1     2   2               1   2   2 1 1   1     2 2     2           1  
'use strict';
 
var errorFactory = require('../util/error-factory');
var AbstractReporter = require('./abstract-reporter');
 
/**
 * Reporter to emit an error on finding the first linting error.
 *
 * Intended for use with CI servers so the build can be failed
 * appropriately when a linting error is found.
 *
 * @extends {AbstractReporter}
 * @constructor
 */
var FailReporter = function()
{
  /**
   * @type {Array}
   */
  this.fails = [];
 
  /**
   * @type {Array}
   */
  this.buffer = [];
};
 
/**
 * Inherit from AbstractReporter.
 *
 * @type {AbstractReporter}
 */
FailReporter.prototype = new AbstractReporter();
 
/**
 * Reset constructor to FailReporter.
 *
 * @type {FailReporter}
 */
FailReporter.prototype.constructor = FailReporter;
 
/**
 * @type {string}
 */
FailReporter.REPORTER_NAME = 'fail';
 
/**
 * @type {function}
 */
FailReporter.prototype.createError = errorFactory('gulp-gjslint');
 
/**
 * @param {File} file
 * @param {string} encoding
 * @param {function} callback
 */
FailReporter.prototype.processFile = function(file, encoding, callback)
{
  if (file.gjslint && file.gjslint.success === false) {
    this.fails.push(file.path);
  }
 
  this.buffer.push(file);
 
  callback();
};
 
/**
 * Emit an error if there were any failures.
 *
 * @param {function} callback
 */
FailReporter.prototype.flush = function(callback)
{
  var errorMsg = [];
 
  if (this.fails.length) {
    errorMsg.push('Linting failed for files: ');
    errorMsg.push(this.fails.join(', '));
 
    this.stream.emit('error', this.createError(errorMsg.join('')));
  }
 
  this.buffer.forEach(function(file) {
    this.stream.push(file);
  }, this);
 
  callback();
};
 
/**
 * @type {FailReporter}
 */
module.exports = FailReporter;