test.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/test
 */
module.exports = test;

/**
 * Returns `true` if test was prepared and added to the queue.
 *
 * @alias module:pete/test
 * @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 test (name, fn, opts, cb) { // eslint-disable-line no-unused-vars
	const options = new RunOptions();
	fn = runner.setOptions(createId(test), options, arguments); // eslint-disable-line prefer-rest-params

	const err = options.areInvalid();
	if (!fn || err) {
		if (err.code !== 'ID_MISMATCH') {
			console.warn(err);
		}
		return false;
	}

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

	return true;
}