<commit_before>const { errorToJson } = require('../util')

function expectError(e1, e2) {
  const ne1 = typeof e1 === 'string' ? new Error(e1) : e1
  const ne2 = typeof e2 === 'string' ? new Error(e2) : e2
  const be1 = get(() => e2.constructor.name) ? errorToJson(ne1) : ne1
  const be2 = get(() => e1.constructor.name) ? errorToJson(ne2) : ne2
  expect(omitStack(be1)).toEqual(omitStack(be2))
}

function omitStack(s) {
  delete s.stack
  return s
}

function get(fn) {
  try {
    return fn()
  } catch (e) {
    return undefined
  }
}

function sleep(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
}

module.exports = {
  expectError,
  sleep
}<commit_msg>refactor error test util<commit_after>const { errorToJson } = require('../util')

function expectError(e1, e2) {
  const ne1 = typeof e1 === 'string' ? new Error(e1) : e1
  const ne2 = typeof e2 === 'string' ? new Error(e2) : e2
  const be1 = get(() => e2.constructor.name) ? errorToJson(ne1) : ne1
  const be2 = get(() => e1.constructor.name) ? errorToJson(ne2) : ne2
  const oe1 = omitStack(be1)
  const oe2 = omitStack(be2)
  expect(oe1).toEqual(oe2)
}

function omitStack(s) {
  delete s.stack
  return s
}

function get(fn) {
  try {
    return fn()
  } catch (e) {
    return undefined
  }
}

function sleep(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms)
  })
}

module.exports = {
  expectError,
  sleep
}
{'fraction_non_alphanumeric': 0.1536293164200141, 'fraction_numerical': 0.031007751937984496, 'mean_word_length': 3.4654088050314464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2935759', 'n_tokens_mistral': 541, 'n_tokens_neox': 537, 'n_words': 129}