<commit_before>'use strict'

const fs     = require('fs')
const path   = require('path')
const assert = require('chai').assert
const temp   = require('temp').track()
const index  = require('./../src/index')

let validFile   = null
let invalidFile = null

describe('index()', function() {

	before(function() {

		validFile = temp.openSync({
			dir    : __dirname,
			suffix : '.js'
		})

		fs.writeFileSync(validFile.path, `const fn = () => {}`)

		invalidFile = temp.openSync({
			dir    : __dirname,
			suffix : '.js'
		})

		fs.writeFileSync(invalidFile.path, `=`)

	})

	it('should return an error when called with a invalid filePath', function() {

		return index(null, '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should return an error when called with a fictive filePath', function() {

		return index('test.js', '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should return an error when called with an invalid JS file and everything else specified', function() {

		return index(invalidFile.path, '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should load JS and transform it to JS when everything specified', function() {

		return index(validFile.path, '/src', '/dist', {}).then(({ data, savePath }) => {

			assert.isString(data)
			assert.isString(savePath)
			assert.strictEqual(savePath.substr(-3), '.js')

		})

	})

	it('should load JS and transform it to JS when distPath not specified', function() {

		return index(validFile.path, '/src', null, {}).then(({ data, savePath }) => {
<commit_msg>New test file for each test<commit_after>'use strict'

const fs     = require('fs')
const path   = require('path')
const assert = require('chai').assert
const temp   = require('temp').track()
const index  = require('./../src/index')

const newFile = function(content, suffix) {

	// File must be in current dir so babel-register can load the plugins and presents
	const file = temp.openSync({
		dir    : __dirname,
		suffix : suffix
	})

	fs.writeFileSync(file.path, content)

	return file

}

describe('index()', function() {

	it('should return an error when called with a invalid filePath', function() {

		return index(null, '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should return an error when called with a fictive filePath', function() {

		return index('test.js', '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should return an error when called with an invalid JS file and everything else specified', function() {

		const file = newFile('=', '.js')

		return index(file.path, '/src', '/dist', {}).then(({ data, savePath }) => {

			throw new Error('Returned without error')

		}, (err) => {

			assert.isNotNull(err)

		})

	})

	it('should load JS and transform it to JS when everything specified', function() {

		const file = newFile('const fn = () => {}', '.js')

		return index(file.path, '/src', '/dist', {}).then(({ data, savePath }) => {

			assert.isString(data)
			assert.isString(savePath)
			assert.strictEqual(savePath.substr(-3), '.js')

		})

	})

	it('should load JS and transform it to JS when distPath not specified', function() {

		const file = newFile('const fn = () => {}', '.js')

		return index(file.path, '/src', null, {}).then(({ data, savePath }) => {

{'fraction_non_alphanumeric': 0.17884666489503057, 'fraction_numerical': 0.0005314908317831517, 'mean_word_length': 3.5349397590361447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '1145603', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1158, 'n_words': 355}