<commit_before>import test from "ava"
import { join } from "path"

import { exec } from "child_process"

const target = join(__dirname, "..", "test-boilerplate")
const execOpts = { cwd: target }

const phenomic = "node ./node_modules/.bin/phenomic"

// cannot be done for now
// see the mess in configurator which use process.argv directly
// and since build.js is spawned, we got too many args and cannot use
// yargs.strict()
// https://github.com/MoOx/phenomic/issues/363
// test.cb("should throw if a CLI flag is NOT recognized", (t) => {
//   const child = exec(
//     `${ phenomic } start --lol --open=false`, execOpts,
//     (err) => {
//       if (err) {
//         clearTimeout(timeout)
//         t.ok(err.message.indexOf("Unknown argument") > -1)
//         t.end()
//       }
//     }
//   )
//
//   const timeout = setTimeout(() => {
//     child.kill()
//     t.fail()
//     t.end()
//   }, 500)
// })

test.cb("should NOT throw if a CLI flag is recognized", (t) => {
  const child = exec(
    `${ phenomic } start --devPort=4000 --open=false`, execOpts,

    // should die quickly...
    (err) => {
      if (err) {
        console.log(err)
        clearTimeout(timeout)
        t.fail()
        t.end()
      }
    }
  )

  // ...or be ok quickly
  // (so we assume it's ok and kill the process, we don't need the actual build)
  const timeout = setTimeout(() => {
    child.kill()
    t.pass()
    t.end()
  }, 500)
})

test.cb("should NOT throw if port is used", (t) => {
  const app = require("express")()

  const server = app.listen(8081, (err) => {
    if (err) {
      t.fail()
      t.end()
    }

    const child = exec(
      `${ phenomic } start --devPort=8081`, execOpts,

      (err) => {
        if (err) {
          console.log(err)
          clearTimeout(timeout)
          t.fail()
          t.end()
        }
      }
    )

    const timeout = setTimeout(() => {<commit_msg>Internal: adjust timing for test and prevent dead server to be opened<commit_after>import test from "ava"
import { join } from "path"

import { exec } from "child_process"

const target = join(__dirname, "..", "test-boilerplate")
const execOpts = { cwd: target }

const phenomic = "node ./node_modules/.bin/phenomic"

// cannot be done for now
// see the mess in configurator which use process.argv directly
// and since build.js is spawned, we got too many args and cannot use
// yargs.strict()
// https://github.com/MoOx/phenomic/issues/363
// test.cb("should throw if a CLI flag is NOT recognized", (t) => {
//   const child = exec(
//     `${ phenomic } start --open=false --lol`, execOpts,
//     (err) => {
//       if (err) {
//         clearTimeout(timeout)
//         t.ok(err.message.indexOf("Unknown argument") > -1)
//         t.end()
//       }
//     }
//   )
//
//   const timeout = setTimeout(() => {
//     child.kill()
//     t.fail()
//     t.end()
//   }, 1000)
// })

test.cb("should NOT throw if a CLI flag is recognized", (t) => {
  const child = exec(
    `${ phenomic } start --open=false --devPort=4000`, execOpts,

    // should die quickly...
    (err) => {
      if (err) {
        console.log(err)
        clearTimeout(timeout)
        t.fail()
        t.end()
      }
    }
  )

  // ...or be ok quickly
  // (so we assume it's ok and kill the process, we don't need the actual build)
  const timeout = setTimeout(() => {
    child.kill()
    t.pass()
    t.end()
  }, 1000)
})

test.cb("should NOT throw if port is used", (t) => {
  const app = require("express")()

  const server = app.listen(8081, (err) => {
    if (err) {
      t.fail()
      t.end()
    }

    const child = exec(
      `${ phenomic } start --open=false --devPort=8081`, execOpts,

      (err) => {
        if (err) {
          console.log(err)
          clearTimeout(timeout)
          t.fail()
          t.end()
        }
      }
    )

    const timeout = setTimeout(() => {
{'fraction_non_alphanumeric': 0.17107629077832007, 'fraction_numerical': 0.011816080143847931, 'mean_word_length': 1.9747899159663866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '2174097', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1280, 'n_words': 368}