<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) {
	const fly = new Fly();
	yield fly.source([[['*.a', ['*.b']]], ['*.c']]);
	t.true('globs' in fly._ && 'files' in fly._, 'create `globs` and `files` keys within `fly._`');
	t.deepEqual(fly._.globs, ['*.a', '*.b', '*.c'], 'flatten nested globs');
	t.deepEqual(fly._.files, [], 'return empty array if no files matched');

	const txt = join(fixtures, '*.txt');
	yield fly.source(txt);
	t.true($.isArray(fly._.globs), 'convert single source string to an array');
	t.equal(fly._.globs[0], txt, 'update internal `source` keys each time');
	t.true($.isArray(fly._.files) && fly._.files.length, 'return an array of relevant files');
	t.equal(fly._.files[0], join(fixtures, 'foo.txt'), 'find the correct files');

	t.end();
}));

test('fly.start', co(function * (t) {<commit_msg>add fly.source test to verify context is returned<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: 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) {
	const fly = new Fly();
	const out = yield fly.source([[['*.a', ['*.b']]], ['*.c']]);
	t.true('globs' in fly._ && 'files' in fly._, 'create `globs` and `files` keys within `fly._`');
	t.deepEqual(fly._.globs, ['*.a', '*.b', '*.c'], 'flatten nested globs');
	t.deepEqual(fly._.files, [], 'return empty array if no files matched');
	t.equal(out, fly, 'returns the bound instance');

	const txt = join(fixtures, '*.txt');
	yield fly.source(txt);
	t.true($.isArray(fly._.globs), 'convert single source string to an array');
	t.equal(fly._.globs[0], txt, 'update internal `source` keys each time');
	t.true($.isArray(fly._.files) && fly._.files.length, 'return an array of relevant files');
	t.equal(fly._.files[0], join(fixtures, 'foo.txt'), 'find the correct files');

	t.end();
}));

test('fly.start', co(function * (t) {
{'fraction_non_alphanumeric': 0.22414943295530354, 'fraction_numerical': 0.011007338225483656, 'mean_word_length': 4.307079646017699, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '167616', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2212, 'n_words': 587}