<commit_before>'use strict';
const fs = require('fs');
const path = require('path');
const test = require('tap').test;
const makeDir = require('make-dir');
const uniqueTempDir = require('unique-temp-dir');
const configManager = require('hullabaloo-config-manager');

const babelConfigHelper = require('../lib/babel-config');

const fixture = name => path.join(__dirname, 'fixture', name);

test('uses default presets when userOptions is "default"', t => {
	const userOptions = 'default';
	const powerAssert = true;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, [
				require.resolve('@ava/babel-preset-stage-4'),
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('uses options from babelrc when userOptions is "inherit"', t => {
	const userOptions = 'inherit';
	const powerAssert = true;

	const projectDir = fixture('babelrc');
	const cacheDir = path.join(uniqueTempDir(), 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.plugins, [require.resolve(fixture('babel-plugin-test-doubler'))]);
			t.same(options.presets, [require.resolve('@ava/babel-preset-stage-4')]);
			const envOptions = options.env[configManager.currentEnv()];
			t.same(envOptions, {
				presets: [
					[
						require.resolve('@ava/babel-preset-transform-test-files'),
						{powerAssert}
					]
				]
			});
		});
});

test('uses userOptions for babel options when userOptions is an object', t => {
	const custom = require.resolve(fixture('empty'));
	const userOptions = {
		presets: [custom],
		plugins: [custom]
	};
	const powerAssert = true;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, userOptions.presets);
			t.same(options.plugins, userOptions.plugins);
			t.same(options.env.development.presets, [
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('should disable power-assert when powerAssert is false', t => {
	const userOptions = 'default';
	const powerAssert = false;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, [
				require.resolve('@ava/babel-preset-stage-4'),
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('caches and uses results', t => {
	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, 'default', true)
		.then(result => {
			const files = fs.readdirSync(cacheDir);
			t.is(files.length, 2);
			t.is(files.filter(f => /\.babel-options\.js$/.test(f)).length, 1);
			t.is(files.filter(f => /\.verifier\.bin$/.test(f)).length, 1);

			const firstCacheKeys = result.cacheKeys;
			const stats = files.map(f => fs.statSync(path.join(cacheDir, f)));
			delete stats[0].atime;
			delete stats[1].atime;

			return babelConfigHelper.build(projectDir, cacheDir, 'default', true)
				.then(result => {
					const newStats = files.map(f => fs.statSync(path.join(cacheDir, f)));
					delete newStats[0].atime;
					delete newStats[1].atime;

					t.same(newStats, stats);
					t.same(result.cacheKeys, firstCacheKeys);
				});
		});
});<commit_msg>Ignore new atimeMs values in babel-config test<commit_after>'use strict';
const fs = require('fs');
const path = require('path');
const test = require('tap').test;
const makeDir = require('make-dir');
const uniqueTempDir = require('unique-temp-dir');
const configManager = require('hullabaloo-config-manager');

const babelConfigHelper = require('../lib/babel-config');

const fixture = name => path.join(__dirname, 'fixture', name);

test('uses default presets when userOptions is "default"', t => {
	const userOptions = 'default';
	const powerAssert = true;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, [
				require.resolve('@ava/babel-preset-stage-4'),
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('uses options from babelrc when userOptions is "inherit"', t => {
	const userOptions = 'inherit';
	const powerAssert = true;

	const projectDir = fixture('babelrc');
	const cacheDir = path.join(uniqueTempDir(), 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.plugins, [require.resolve(fixture('babel-plugin-test-doubler'))]);
			t.same(options.presets, [require.resolve('@ava/babel-preset-stage-4')]);
			const envOptions = options.env[configManager.currentEnv()];
			t.same(envOptions, {
				presets: [
					[
						require.resolve('@ava/babel-preset-transform-test-files'),
						{powerAssert}
					]
				]
			});
		});
});

test('uses userOptions for babel options when userOptions is an object', t => {
	const custom = require.resolve(fixture('empty'));
	const userOptions = {
		presets: [custom],
		plugins: [custom]
	};
	const powerAssert = true;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, userOptions.presets);
			t.same(options.plugins, userOptions.plugins);
			t.same(options.env.development.presets, [
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('should disable power-assert when powerAssert is false', t => {
	const userOptions = 'default';
	const powerAssert = false;

	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, userOptions, powerAssert)
		.then(result => {
			const options = result.getOptions();

			t.false(options.babelrc);
			t.same(options.presets, [
				require.resolve('@ava/babel-preset-stage-4'),
				[
					require.resolve('@ava/babel-preset-transform-test-files'),
					{powerAssert}
				]
			]);
		});
});

test('caches and uses results', t => {
	const projectDir = uniqueTempDir();
	const cacheDir = path.join(projectDir, 'cache');
	return babelConfigHelper.build(projectDir, cacheDir, 'default', true)
		.then(result => {
			const files = fs.readdirSync(cacheDir);
			t.is(files.length, 2);
			t.is(files.filter(f => /\.babel-options\.js$/.test(f)).length, 1);
			t.is(files.filter(f => /\.verifier\.bin$/.test(f)).length, 1);

			const firstCacheKeys = result.cacheKeys;
			const stats = files.map(f => fs.statSync(path.join(cacheDir, f)));
			delete stats[0].atime;
			delete stats[0].atimeMs;
			delete stats[1].atime;
			delete stats[1].atimeMs;

			return babelConfigHelper.build(projectDir, cacheDir, 'default', true)
				.then(result => {
					const newStats = files.map(f => fs.statSync(path.join(cacheDir, f)));
					delete newStats[0].atime;
					delete newStats[0].atimeMs;
					delete newStats[1].atime;
					delete newStats[1].atimeMs;

					t.same(newStats, stats);
					t.same(result.cacheKeys, firstCacheKeys);
				});
		});
});
{'fraction_non_alphanumeric': 0.1614487415592388, 'fraction_numerical': 0.0029465930018416206, 'mean_word_length': 4.175349428208386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '2808678', 'n_tokens_mistral': 3046, 'n_tokens_neox': 2621, 'n_words': 512}