<commit_before>const { spawn } = require('child_process')
const test = require('ava')
const os = require('os')

const m = require('..')

test('should work with a single pid', async t => {
  const pid = process.pid

  const result = await m(pid)

  t.log(result)

  t.is(typeof result, 'object')

  t.is(typeof result, 'object', 'result')
  t.is(typeof result.cpu, 'number', 'cpu')
  t.false(isNaN(result.cpu), 'cpu')
  t.is(typeof result.memory, 'number', 'memory')
  // z/OS does not report memory
  if (process.platform != "os390")
    t.false(isNaN(result.memory), 'memory')
  t.is(typeof result.ppid, 'number', 'ppid')
  t.false(isNaN(result.ppid), 'ppid')
  t.is(typeof result.pid, 'number', 'pid')
  t.false(isNaN(result.pid), 'pid')
  t.is(typeof result.elapsed, 'number', 'elapsed')
  t.false(isNaN(result.elapsed), 'elapsed')
  t.is(typeof result.timestamp, 'number', 'timestamp')
  t.false(isNaN(result.timestamp), 'timestamp')
})

test('should work with an array of pids', async t => {
  const child = spawn(
    'node',
    ['-e', 'console.log(123); var c = 0; while(true) {c = Math.pow(c, c);}'],
    { windowsHide: true }
  )
  const ppid = process.pid
  const pid = child.pid

  await t.notThrows(() =>
    new Promise((resolve, reject) => {
      child.stdout.on('data', d => resolve(d.toString()))
      child.stderr.on('data', d => reject(d.toString()))
      child.on('error', reject)
      child.on('exit', reject)
    }),
  'script not executed'
  )

  const pids = [ppid, pid]
  let result
  try {
    result = await m(pids)
    child.kill()
  } catch (err) {
    child.kill()
    t.notThrows(() => { throw err })
  }

  t.log(result)

  t.is(typeof result, 'object')
  t.deepEqual(Object.keys(result).sort(), pids.map(pid => pid.toString()).sort())

  pids.forEach(pid => {
    t.is(typeof result[pid], 'object', 'result')
    t.is(typeof result[pid].cpu, 'number', 'cpu')
    t.false(isNaN(result[pid].cpu), 'cpu')
    t.is(typeof result[pid].memory, 'number', 'memory')
    // z/OS does not report memory
    if (process.platform != "os390")
      t.false(isNaN(result.memory), 'memory')
    // z/OS does not report memory
    if (process.platform != "os390")
      t.false(isNaN(result[pid].memory), 'memory')
    t.is(typeof result[pid].ppid, 'number', 'ppid')
    t.false(isNaN(result[pid].ppid), 'ppid')
    t.is(typeof result[pid].pid, 'number', 'pid')
    t.false(isNaN(result[pid].pid), 'pid')
    t.is(typeof result[pid].elapsed, 'number', 'elapsed')
    t.false(isNaN(result[pid].elapsed), 'elapsed')
    t.is(typeof result[pid].timestamp, 'number', 'timestamp')<commit_msg>Update integration.js<commit_after>const { spawn } = require('child_process')
const test = require('ava')
const os = require('os')

const m = require('..')

test('should work with a single pid', async t => {
  const pid = process.pid

  const result = await m(pid)

  t.log(result)

  t.is(typeof result, 'object')

  t.is(typeof result, 'object', 'result')
  t.is(typeof result.cpu, 'number', 'cpu')
  t.false(isNaN(result.cpu), 'cpu')
  t.is(typeof result.memory, 'number', 'memory')
  // z/OS does not report memory
  if (process.platform !== "os390") {
    t.false(isNaN(result.memory), 'memory')
  }
  t.is(typeof result.ppid, 'number', 'ppid')
  t.false(isNaN(result.ppid), 'ppid')
  t.is(typeof result.pid, 'number', 'pid')
  t.false(isNaN(result.pid), 'pid')
  t.is(typeof result.elapsed, 'number', 'elapsed')
  t.false(isNaN(result.elapsed), 'elapsed')
  t.is(typeof result.timestamp, 'number', 'timestamp')
  t.false(isNaN(result.timestamp), 'timestamp')
})

test('should work with an array of pids', async t => {
  const child = spawn(
    'node',
    ['-e', 'console.log(123); var c = 0; while(true) {c = Math.pow(c, c);}'],
    { windowsHide: true }
  )
  const ppid = process.pid
  const pid = child.pid

  await t.notThrows(() =>
    new Promise((resolve, reject) => {
      child.stdout.on('data', d => resolve(d.toString()))
      child.stderr.on('data', d => reject(d.toString()))
      child.on('error', reject)
      child.on('exit', reject)
    }),
  'script not executed'
  )

  const pids = [ppid, pid]
  let result
  try {
    result = await m(pids)
    child.kill()
  } catch (err) {
    child.kill()
    t.notThrows(() => { throw err })
  }

  t.log(result)

  t.is(typeof result, 'object')
  t.deepEqual(Object.keys(result).sort(), pids.map(pid => pid.toString()).sort())

  pids.forEach(pid => {
    t.is(typeof result[pid], 'object', 'result')
    t.is(typeof result[pid].cpu, 'number', 'cpu')
    t.false(isNaN(result[pid].cpu), 'cpu')
    t.is(typeof result[pid].memory, 'number', 'memory')
    // z/OS does not report memory
    if (process.platform !== "os390") {
      t.false(isNaN(result.memory), 'memory')
      t.false(isNaN(result[pid].memory), 'memory')
    }

    t.is(typeof result[pid].ppid, 'number', 'ppid')
    t.false(isNaN(result[pid].ppid), 'ppid')
    t.is(typeof result[pid].pid, 'number', 'pid')
    t.false(isNaN(result[pid].pid), 'pid')
    t.is(typeof result[pid].elapsed, 'number', 'elapsed')
    t.false(isNaN(result[pid].elapsed), 'elapsed')
    t.is(typeof result[pid].timestamp, 'number', 'timestamp')
{'fraction_non_alphanumeric': 0.19945830915070614, 'fraction_numerical': 0.00444960340491391, 'mean_word_length': 3.632616487455197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2599504', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1865, 'n_words': 408}