<commit_before>/* @flow */

import type { PathObject } from '../../../core/utils/path'

const Promise = require('bluebird')
const fs = require('fs-extra')
const path = require('path')

const { getPath } = require('../../../core/utils/path')

Promise.promisifyAll(fs)

class SyncDirTestHelpers {
  root: string

  constructor (root: string) {
    this.root = root
  }

  abspath (target: string|PathObject): string {
    return path.join(this.root, getPath(target))
  }

  existsSync (target: string|PathObject): Promise<bool> {
    return fs.existsSync(this.abspath(target))
  }

  async ensureDir (target: string|PathObject) {
    await fs.ensureDir(this.abspath(target))
  }

  async unlink (target: string|PathObject) {
    await fs.unlinkAsync(this.abspath(target))
  }

  async rmdir (target: string|PathObject) {
    await fs.rmdirSync(this.abspath(target))
  }

  async readFile (target: string|PathObject): Promise<string> {
    return fs.readFile(this.abspath(target), 'utf8')
  }
}

module.exports = {
  SyncDirTestHelpers
}<commit_msg>test/support/helpers/sync_dir: Introduce outputFile()<commit_after>/* @flow */

import type { PathObject } from '../../../core/utils/path'

const Promise = require('bluebird')
const fs = require('fs-extra')
const path = require('path')

const { getPath } = require('../../../core/utils/path')

Promise.promisifyAll(fs)

class SyncDirTestHelpers {
  root: string

  constructor (root: string) {
    this.root = root
  }

  abspath (target: string|PathObject): string {
    return path.join(this.root, getPath(target))
  }

  existsSync (target: string|PathObject): Promise<bool> {
    return fs.existsSync(this.abspath(target))
  }

  async ensureDir (target: string|PathObject) {
    await fs.ensureDir(this.abspath(target))
  }

  async unlink (target: string|PathObject) {
    await fs.unlinkAsync(this.abspath(target))
  }

  async rmdir (target: string|PathObject) {
    await fs.rmdirSync(this.abspath(target))
  }

  async readFile (target: string|PathObject): Promise<string> {
    return fs.readFile(this.abspath(target), 'utf8')
  }

  async outputFile (target: string|PathObject, data: string) {
    return fs.outputFile(this.abspath(target), data)
  }
}

module.exports = {
  SyncDirTestHelpers
}
{'fraction_non_alphanumeric': 0.14869063470927651, 'fraction_numerical': 0.000887705281846427, 'mean_word_length': 4.0088888888888885, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5504093', 'n_tokens_mistral': 770, 'n_tokens_neox': 763, 'n_words': 151}