'use strict';
var es = require('event-stream');
var Mocha = require('mocha');

module.exports = function (options) {
	var mocha = new Mocha(options);

	return es.through(function (file) {
		mocha.addFile(file.path);
		this.emit('data', file);
	}, function () {
		mocha.run(function (errCount) {
			if (errCount > 0) {
				return this.emit('error', new Error('gulp-mocha: ' + errCount + ' ' + (errCount === 1 ? 'test' : 'tests') + ' failed.'));
			}

			this.emit('end');
		}.bind(this));
	});
};

'use strict';
var es = require('event-stream');
var Mocha = require('mocha');
var path = require('path');

module.exports = function (options) {
	var mocha = new Mocha(options);

	return es.through(function (file) {
		delete require.cache[require.resolve(path.resolve(file.path))];
		mocha.addFile(file.path);
		this.emit('data', file);
	}, function () {
		mocha.run(function (errCount) {
			if (errCount > 0) {
				return this.emit('error', new Error('gulp-mocha: ' + errCount + ' ' + (errCount === 1 ? 'test' : 'tests') + ' failed.'));
			}

			this.emit('end');
		}.bind(this));
	});
};

Make gulp-mocha comatible with watch
Make gulp-mocha comatible with watch

Since mocha uses `require` to load tests - we need either run mocha in
spawned process or clear requires cache.
