<commit_before>/* global it, expect, afterAll */
const fse = require('fs-extra')
const Path = require('path')
const babel = require('babel-core')
const plugin = require('..')

const fixtureDirPath = Path.resolve(__dirname, "fixtures")
const resultsDir = Path.join(__dirname, "output")

fse
  .emptyDirSync(resultsDir)

fse
  .readdirSync(fixtureDirPath)
  .filter(item => item.endsWith('.js'))
  .forEach(item => {
    const filename = Path.join(fixtureDirPath, item)
    const babelOpts = {
      plugins: [
        "babel-plugin-syntax-decorators",
        "babel-plugin-syntax-class-properties",
        plugin
      ]
    }
    const result = babel.transformFileSync(filename, babelOpts).code
    it(item, () => {
      expect(result).toMatchSnapshot()
    })
  })

afterAll(() => {
  // Log the results into individual files. These are for manual spot-checking, not for automated tests.
  try {
    const sciptName = Path.basename(__filename)
    const snapshots = require(Path.join(__dirname, '__snapshots__', `${sciptName}.snap`))
    Object.keys(snapshots).forEach(item => {
      const filename = item.split('.js')[0] + '.js'
      const filepath = Path.join(resultsDir, filename)
      const escapedCode = snapshots[item]
      const plainCode = escapedCode
        .trim()
        .slice(1, -1) // Remove the surrounding quotes
        .replace(/\\"/g, '"')
      fse.writeFileSync(filepath, plainCode)
    })
  } catch (error) {
    console.error(error)
  }
})<commit_msg>tests: Create the result file right away<commit_after>/* global it, expect */
const fse = require('fs-extra')
const Path = require('path')
const babel = require('babel-core')
const plugin = require('..')

const fixtureDirPath = Path.resolve(__dirname, 'fixtures')
const resultsDir = Path.join(__dirname, 'output')

fse
  .emptyDirSync(resultsDir)

fse
  .readdirSync(fixtureDirPath)
  .filter(item => item.endsWith('.js'))
  .forEach(filename => {
    const filepath = Path.join(fixtureDirPath, filename)
    const babelOpts = {
      plugins: [
        'babel-plugin-syntax-decorators',
        'babel-plugin-syntax-class-properties',
        plugin
      ]
    }
    const result = babel.transformFileSync(filepath, babelOpts).code
    const resultFilepath = Path.join(resultsDir, filename)
    fse.writeFileSync(resultFilepath, result)
    it(filename, () => {
      expect(result).toMatchSnapshot()
    })
  })
{'fraction_non_alphanumeric': 0.14178482068390325, 'fraction_numerical': 0.0012510425354462051, 'mean_word_length': 3.353901996370236, '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': '1719581', 'n_tokens_mistral': 752, 'n_tokens_neox': 744, 'n_words': 160}