<commit_before>'use strict'

const async = require('async')
const proxyquire = require('proxyquire')
const { Readable } = require('stream')

exports.loadLib = (file) => {
  // Spy on the async module.
  spyOn(async, 'eachOfLimit').and.callThrough()

  // Stub out the fs(-extra) module with spies.
  let fs = jasmine.createSpyObj('fs', [
    'appendFileSync',
    'createFileSync',
    'readFile',
    'readFileSync',
    'removeSync',
    'truncateSync',
    'writeFileSync'
  ])

  // Stub out the got module with a spy.
  let got = jasmine.createSpyObj('got', ['stream'])
  got.stream.and.callFake(url => {
    return new Readable({
      read () {
        if (this.alreadySent) {
          this.push(null)
        } else {
          this.push('test')
          this.alreadySent = true
        }
      }
    })
  })

  // Stub out the Polly SDK.
  // let getSynthesizeSpeechUrl = jasmine.createSpy('getSynthesizeSpeechUrl');
  // let PollyStub = function() {
  //   this.getSynthesizeSpeechUrl = getSynthesizeSpeechUrl;
  // };
  let PollyStub = jasmine.createSpy('Polly')
  let pollyStub = {
    Presigner: PollyStub
  }

  let spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
    if (type === 'close') { callback() }
  })
  let spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
  let spawn = jasmine.createSpy('spawn').and.callFake(() => {
    return {
      on: spawnOnSpy,
      stderr: {
        on: spawnStderrOn
      }
    }
  })

  // Load the library module.
  let lib = proxyquire(`../lib/${file}`, {
    async: async,
    'aws-sdk/clients/polly': pollyStub,
    child_process: { spawn }, // eslint-disable-line camelcase
    'fs-extra': fs,
    got: got<commit_msg>refactor(test): Clean up test helper module<commit_after>const async = require('async')
const proxyquire = require('proxyquire')
const { Readable } = require('stream')

exports.loadLib = (file) => {
  // Spy on the async module.
  spyOn(async, 'eachOfLimit').and.callThrough()

  // Stub out the fs(-extra) module with spies.
  let fs = jasmine.createSpyObj('fs', [
    'appendFileSync',
    'createFileSync',
    'readFile',
    'readFileSync',
    'removeSync',
    'truncateSync',
    'writeFileSync'
  ])

  // Stub out the got module with a spy.
  let got = jasmine.createSpyObj('got', ['stream'])
  got.stream.and.callFake(url => {
    return new Readable({
      read () {
        if (this.alreadySent) {
          this.push(null)
        } else {
          this.push('test')
          this.alreadySent = true
        }
      }
    })
  })

  // Stub out the Polly SDK.
  let PollyStub = jasmine.createSpy('Polly')
  let pollyStub = {
    Presigner: PollyStub
  }

  let spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
    if (type === 'close') { callback() }
  })
  let spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
  let spawn = jasmine.createSpy('spawn').and.callFake(() => {
    return {
      on: spawnOnSpy,
      stderr: {
        on: spawnStderrOn
      }
    }
  })

  // Load the library module.
  let lib = proxyquire(`../lib/${file}`, {
    async: async,
    'aws-sdk/clients/polly': pollyStub,
    child_process: { spawn }, // eslint-disable-line camelcase
    'fs-extra': fs,
    got: got
{'fraction_non_alphanumeric': 0.15316144874155924, 'fraction_numerical': 0.0, 'mean_word_length': 2.645413870246085, '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': '5347192', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1121, 'n_words': 234}