<commit_before>const spawn = require('child_process').spawn
const parse = require('safe-json-parse')
const concat = require('concat-stream')
const mapLimit = require('map-limit')
const readdirp = require('readdirp')
const rimraf = require('rimraf')
const pump = require('pump')
const path = require('path')
const test = require('tape')
const fs = require('fs')

test('should create files', function (t) {
  t.plan(16)

  const route = path.join(process.cwd(), 'tmp')
  const cmd = path.join(__dirname, 'bin/cli.js')
  const name = 'test'

  const fns = [ runInit, verifyFiles, verifyPkg, clean ]
  mapLimit(fns, 1, function (fn, cb) { fn(cb) }, function (err) {
    t.error(err)
  })

  function runInit (next) {
    const ps = spawn(cmd, [ '-d', route, '-n', name ])
    ps.stdout.pipe(process.stdout) // uncomment in case of bugs
    ps.stderr.pipe(process.stderr)
    ps.stdout.on('end', next)
  }

  function verifyFiles (next) {
    const opts = { root: path.join(route, name) }
    readdirp(opts).pipe(concat({ object: true }, sink))

    function sink (arr) {
      t.ok(Array.isArray(arr), 'is array')

      arr = arr.map(function (obj) { return obj.path })
      t.notEqual(arr.indexOf('.gitignore'), -1, '.gitignore exists')
      t.notEqual(arr.indexOf('.travis.yml'), -1, '.travis.yml exists')
      t.notEqual(arr.indexOf('LICENSE'), -1, 'LICENSE exists')
      t.notEqual(arr.indexOf('README.md'), -1, 'README.md exists')
      t.notEqual(arr.indexOf('index.js'), -1, 'index.js exists')
      t.notEqual(arr.indexOf('package.json'), -1, 'package.json exists')
      t.notEqual(arr.indexOf('test.js'), -1, 'test.js exists')
      t.notEqual(arr.indexOf('app-main/index.js'), -1, 'am/index.js exists')
      t.notEqual(arr.indexOf('app-main/package.json'), -1, 'am/package.json exists')
<commit_msg>test: fold file check boilerplate<commit_after>const spawn = require('child_process').spawn
const parse = require('safe-json-parse')
const concat = require('concat-stream')
const mapLimit = require('map-limit')
const readdirp = require('readdirp')
const rimraf = require('rimraf')
const pump = require('pump')
const path = require('path')
const test = require('tape')
const fs = require('fs')

test('should create files', function (t) {
  t.plan(16)

  const route = path.join(process.cwd(), 'tmp')
  const cmd = path.join(__dirname, 'bin/cli.js')
  const name = 'test'

  const fns = [ runInit, verifyFiles, verifyPkg, clean ]
  mapLimit(fns, 1, function (fn, cb) { fn(cb) }, function (err) {
    t.error(err)
  })

  function runInit (next) {
    const ps = spawn(cmd, [ '-d', route, '-n', name ])
    ps.stdout.pipe(process.stdout) // uncomment in case of bugs
    ps.stderr.pipe(process.stderr)
    ps.stdout.on('end', next)
  }

  function verifyFiles (next) {
    const opts = { root: path.join(route, name) }
    readdirp(opts).pipe(concat({ object: true }, sink))

    function sink (arr) {
      t.ok(Array.isArray(arr), 'is array')

      const files = [ '.gitignore', '.travis.yml', 'LICENSE', 'README.md',
        'index.js', 'package.json', 'test.js', 'app-main/index.js',
        'app-main/package.json' ]

      arr = arr.map(function (obj) { return obj.path })
      files.forEach(function verifyExists (name) {
        t.notEqual(arr.indexOf(name), -1, name + ' exists')
      })

{'fraction_non_alphanumeric': 0.17981263221517074, 'fraction_numerical': 0.004835297673012995, 'mean_word_length': 3.6423562412342214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1472389', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1123, 'n_words': 266}