<commit_before>import test, { beforeEach, afterEach } from 'ava'
import fs from 'fs'
import path from 'path'
import rimraf from 'rimraf'

import { FileService } from '../../src/services/file'

const tmpData = path.join(__dirname, './env-file')

let fileService
let configService

beforeEach('init temp files for tests', t => {
  fs.mkdirSync(tmpData)
  fs.mkdirSync(path.join(tmpData, 'scripts'))
  fs.mkdirSync(path.join(tmpData, 'files'))
  fs.writeFileSync(path.join(tmpData, 'scripts/test1.sh'), '')
  fs.writeFileSync(path.join(tmpData, 'scripts/test2.js'), '')
})

beforeEach('init service', t => {
  configService = {
    folderPath: tmpData,
    scriptExtension: ['.sh']
  }
  fileService = new FileService(configService)
})

afterEach.always('clean temp files', t => {
  rimraf.sync(tmpData)
})

test('FileService#scripts should return name and path of valid scripts', t => {
  t.deepEqual(fileService.scripts.map(el => el.script), ['test1'])

  configService.scriptExtension = ['.js', '.sh', '.flg']
  t.deepEqual(fileService.scripts.map(el => el.script), ['test1', 'test2'])
})

test.todo('FileService#modules should return name and path of valid modules')
test.todo('FileService#modules should return target and source of each file in modules')
test.todo('FileService#runScript should call chmod')
test.todo('FileService#runScript should call execFile')
test.todo(`FileService#runScript should rethrows BadScriptPermission when 'EACCESS' error is thrown`)<commit_msg>Add test for modules attribute in FileService<commit_after>import test, { beforeEach, afterEach } from 'ava'
import fs from 'fs'
import path from 'path'
import rimraf from 'rimraf'

import { FileService } from '../../src/services/file'

const tmpData = path.join(__dirname, './env-file')

let fileService
let configService

beforeEach('init temp files for tests', t => {
  fs.mkdirSync(tmpData)
  fs.mkdirSync(path.join(tmpData, 'scripts'))
  fs.mkdirSync(path.join(tmpData, 'files'))

  fs.writeFileSync(path.join(tmpData, 'scripts/test1.sh'), '')
  fs.writeFileSync(path.join(tmpData, 'scripts/test2.js'), '')

  fs.mkdirSync(path.join(tmpData, 'files/module1'))
  fs.mkdirSync(path.join(tmpData, 'files/"module 2"'))
  fs.mkdirSync(path.join(tmpData, 'files/badmodule'))
  fs.writeFileSync(path.join(tmpData, 'files/"module 2"/settings.json'), '[]')
  fs.writeFileSync(path.join(tmpData, 'files/module1/settings.json'), '[]')
})

beforeEach('init service', t => {
  configService = {
    folderPath: tmpData,
    scriptExtension: ['.sh']
  }
  fileService = new FileService(configService)
})

afterEach.always('clean temp files', t => {
  rimraf.sync(tmpData)
})

test('FileService#scripts should return name and path of valid scripts', t => {
  t.deepEqual(fileService.scripts.map(el => el.script), ['test1'])
  t.is(fileService.scripts.filter(el => ('path' in el)).length, 1)

  configService.scriptExtension = ['.js', '.sh', '.flg']
  t.deepEqual(fileService.scripts.map(el => el.script), ['test1', 'test2'])
  t.is(fileService.scripts.filter(el => ('path' in el)).length, 2)
})

test('FileService#modules should return name and path of valid modules', t => {
  t.deepEqual(fileService.modules.map(el => el.module), ['module-2', 'module1'])
  t.is(fileService.modules.filter(el => ('path' in el)).length, 2)
})

test.todo('FileService#modules should return target and source of each file in modules')
test.todo('FileService#runScript should call chmod')
test.todo('FileService#runScript should call execFile')
test.todo(`FileService#runScript should rethrows BadScriptPermission when 'EACCESS' error is thrown`)
{'fraction_non_alphanumeric': 0.160734149054505, 'fraction_numerical': 0.0052836484983314795, 'mean_word_length': 5.377659574468085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '6695005', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1159, 'n_words': 275}