<commit_before>'use strict';

const join = require('path').join;
const Promise = require('bluebird');
const test = require('tape').test;
const $ = require('../lib/fn');
const Fly = require('../lib');
const co = Promise.coroutine;

const fixtures = join(__dirname, 'fixtures');
// const flyfile = join(fixtures, 'flyfile.js');

test('fly.prototype', t => {
	t.ok(Fly !== undefined, 'is defined');
	const _ = Fly.prototype;

	['source', 'target', 'emit', 'on', 'clear',
	'start', 'serial', 'parallel']
		.forEach(cmd => {
			t.equal(typeof _[cmd], 'function', `fly.${cmd} is defined`);
		});

	t.end();
});

test('fly.constructor', t => {
	const fake = {
		file: 'fake',
		pwd: fixtures,
		tasks: {a: '1'},
		plugins: [1, 2, 3]
	};

	const fly1 = new Fly();
	t.true(fly1 instanceof Fly, 'instance retains Fly classification');
	t.true(fly1.file === undefined, '`fly.file` is `undefined` by default');
	t.true(fly1.root === process.cwd(), '`fly.root` is `process.cwd()` by default');
	t.true($.isObject(fly1.$), '`fly.$` core utilities are attached');
	t.true($.isArray(fly1.plugins) && !fly1.plugins.length, '`fly.plugins` is an empty array by default');
	t.true($.isObject(fly1.tasks) && $.isEmptyObj(fly1.tasks), '`fly.tasks` is an empty object by default');
	t.true($.isEmptyObj(fly1._), '`fly._` is an empty object on init');

	const fly2 = new Fly(fake);
	t.equal(fly2.file, fake.file, 'accept custom `file` value');
	t.equal(fly2.plugins, fake.plugins, 'accept custom `plugins` value');
	t.equal(fly2.root, fake.pwd, 'accept custom `root` or `pwd` value');
	t.equal(fly2.tasks, fake.tasks, 'accept custom `tasks` value');

	t.end();
});

test('fly.init', co(function * (t) {
	const RDY = '_ready';
	const fly1 = new Fly({
		tasks: {
			a: function * () {
				t.equal(this, fly1, 'bind tasks to fly instance');
			}
		}
	});

	t.false(fly1[RDY], 'is not ready before `fly.init`');

	fly1.init();

	t.true(fly1[RDY], 'is ready after `fly.init`');

	fly1.tasks.a();

	const fly2 = new Fly({tasks: [1, 2, 3]});
	fly2.on('tasks_force_object', () => {
		t.pass('emit an error if `tasks` is not an object');
	});
	fly2.init();

	t.end();
}));

test('fly.source', co(function * (t) {
	t.plan(10);

	const fly = new Fly();
	const glob1 = ['*.a', '*.b', '*.c'];
	const glob2 = join(fixtures, '*.*');
	const opts1 = {ignore: 'foo'};

	fly.on('globs_no_match', (g, o) => {
		t.pass('notify when globs match no files');
		t.deepEqual(g, glob1, 'warning receives the flattened globs');
		t.deepEqual(o, opts1, 'warning receives the `globby` options');
	});

	const out = yield fly.source([[['*.a', ['*.b']]], ['*.c']], opts1);
	t.true('globs' in fly._ && 'files' in fly._, 'create `globs` and `files` keys within `fly._`');
	t.deepEqual(fly._.globs, glob1, 'flatten nested globs');
	t.deepEqual(fly._.files, [], 'return empty array if no files matched');
	t.equal(out, fly, 'returns the bound instance');

	yield fly.source(glob2);
	t.true($.isArray(fly._.globs), 'wrap a single glob string as an array');
	t.equal(fly._.globs[0], glob2, 'update internal `source` keys each time');
	t.true($.isArray(fly._.files), 'return an array of relevant files');
	t.equal(fly._.files.length, 3, 'accepts wildcard extensions; finds all files');
}));

test('fly.start', co(function * (t) {
	let val;
	const RDY = '_ready';

	t.plan(14);

	const fly1 = new Fly({
		tasks: {
			a: function * () {
				val = 5;
				t.pass('execute a task programmatically');
			}
		}
	});

	t.false(fly1[RDY], 'not yet initialized');
	yield fly1.start('a');
	t.equal(val, 5, 'truly `await` a task\'s completion');
	t.true(fly1[RDY], 'ran `fly.init` because was not initialized');

	const fly2 = new Fly({
		tasks: {
			a: function * () {},
			err: function * () {
				throw new Error();
			}<commit_msg>test if fly.source accepts glob-options<commit_after>'use strict';

const join = require('path').join;
const Promise = require('bluebird');
const test = require('tape').test;
const $ = require('../lib/fn');
const Fly = require('../lib');
const co = Promise.coroutine;

const fixtures = join(__dirname, 'fixtures');
// const flyfile = join(fixtures, 'flyfile.js');

test('fly.prototype', t => {
	t.ok(Fly !== undefined, 'is defined');
	const _ = Fly.prototype;

	['source', 'target', 'emit', 'on', 'clear',
	'start', 'serial', 'parallel']
		.forEach(cmd => {
			t.equal(typeof _[cmd], 'function', `fly.${cmd} is defined`);
		});

	t.end();
});

test('fly.constructor', t => {
	const fake = {
		file: 'fake',
		pwd: <PASSWORD>,
		tasks: {a: '1'},
		plugins: [1, 2, 3]
	};

	const fly1 = new Fly();
	t.true(fly1 instanceof Fly, 'instance retains Fly classification');
	t.true(fly1.file === undefined, '`fly.file` is `undefined` by default');
	t.true(fly1.root === process.cwd(), '`fly.root` is `process.cwd()` by default');
	t.true($.isObject(fly1.$), '`fly.$` core utilities are attached');
	t.true($.isArray(fly1.plugins) && !fly1.plugins.length, '`fly.plugins` is an empty array by default');
	t.true($.isObject(fly1.tasks) && $.isEmptyObj(fly1.tasks), '`fly.tasks` is an empty object by default');
	t.true($.isEmptyObj(fly1._), '`fly._` is an empty object on init');

	const fly2 = new Fly(fake);
	t.equal(fly2.file, fake.file, 'accept custom `file` value');
	t.equal(fly2.plugins, fake.plugins, 'accept custom `plugins` value');
	t.equal(fly2.root, fake.pwd, 'accept custom `root` or `pwd` value');
	t.equal(fly2.tasks, fake.tasks, 'accept custom `tasks` value');

	t.end();
});

test('fly.init', co(function * (t) {
	const RDY = '_ready';
	const fly1 = new Fly({
		tasks: {
			a: function * () {
				t.equal(this, fly1, 'bind tasks to fly instance');
			}
		}
	});

	t.false(fly1[RDY], 'is not ready before `fly.init`');

	fly1.init();

	t.true(fly1[RDY], 'is ready after `fly.init`');

	fly1.tasks.a();

	const fly2 = new Fly({tasks: [1, 2, 3]});
	fly2.on('tasks_force_object', () => {
		t.pass('emit an error if `tasks` is not an object');
	});
	fly2.init();

	t.end();
}));

test('fly.source', co(function * (t) {
	t.plan(12);

	const fly = new Fly();
	const glob1 = ['*.a', '*.b', '*.c'];
	const glob2 = join(fixtures, '*.*');
	const opts1 = {ignore: 'foo'};

	fly.on('globs_no_match', (g, o) => {
		t.pass('notify when globs match no files');
		t.deepEqual(g, glob1, 'warning receives the flattened globs');
		t.deepEqual(o, opts1, 'warning receives the `globby` options');
	});

	const out = yield fly.source([[['*.a', ['*.b']]], ['*.c']], opts1);
	t.true('globs' in fly._ && 'files' in fly._, 'create `globs` and `files` keys within `fly._`');
	t.deepEqual(fly._.globs, glob1, 'flatten nested globs');
	t.deepEqual(fly._.files, [], 'return empty array if no files matched');
	t.equal(out, fly, 'returns the bound instance');

	yield fly.source(glob2);
	t.true($.isArray(fly._.globs), 'wrap a single glob string as an array');
	t.equal(fly._.globs[0], glob2, 'update internal `source` keys each time');
	t.true($.isArray(fly._.files), 'return an array of relevant files');
	t.equal(fly._.files.length, 3, 'accepts wildcard extensions; finds all files');

	yield fly.source(glob2, {ignore: join(fixtures, 'flyfile.js')});
	t.equal(fly._.files.length, 2, 'send config options to `globby` (ignore key)');
}));

test('fly.start', co(function * (t) {
	let val;
	const RDY = '_ready';

	t.plan(14);

	const fly1 = new Fly({
		tasks: {
			a: function * () {
				val = 5;
				t.pass('execute a task programmatically');
			}
		}
	});

	t.false(fly1[RDY], 'not yet initialized');
	yield fly1.start('a');
	t.equal(val, 5, 'truly `await` a task\'s completion');
	t.true(fly1[RDY], 'ran `fly.init` because was not initialized');

	const fly2 = new Fly({
		tasks: {
			a: function * () {},
			err: function * () {
				throw new Error();
			}
{'fraction_non_alphanumeric': 0.21374740124740124, 'fraction_numerical': 0.014033264033264034, 'mean_word_length': 4.097350993377484, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4378439', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2850, 'n_words': 770}