skip.js

const getReporters = require('./lib/getReporters.js');
const runner = require('./lib/runner.js');
const enqueue = require('./lib/runnerQueue.js');
const createId = require('./lib/createId.js');
const RunOptions = require('./lib/RunOptions.js');

/**
 * @module pete/skip
 */
module.exports = skip;

/**
 * Prepare test but override it so it will not really be run.
 * It will be reported as "skipped".
 *
 * Returns `true` if test was prepared and added to the queue.
 *
 * @alias module:pete/skip
 * @param {string}                            [name]
 * @param {Function|string}                   fn       function to run, or path to file that calls any combination of `test`, `skip` and/or `todo`
 * @param {module:pete/lib/RunOptions|object} [opts]
 * @param {Function}                          [cb]     function to call back with array of results
 * @return {boolean}
 */
function skip (name, fn, opts, cb) { // eslint-disable-line no-unused-vars
	const options = new RunOptions();
	fn = runner.setOptions(createId(skip), options, arguments); // eslint-disable-line prefer-rest-params

	if (!fn || options.areInvalid()) {
		return false;
	}

	options.runType = 'skip';
	options.exitOnError = false;

	enqueue(runner.createRun(fn, options), options, 'skip', getReporters(options.reporters));

	return true;
}