<commit_before>// this is just a test of the AbortController polyfill
// which is a little bit weird, since that's not about lru caching
// at all, so it's tempting to think that this module should
// pull it in as a dep or something.  that would be the
// javascripty thing to do, right?  but it would mean that
// this is no longer a zero-deps module, so meh.  it's fine.
global.AbortController = null
global.AbortSignal = null

const t = require('tap')

const LRUCache = require('../')
const { AbortController, AbortSignal } = LRUCache

t.type(AbortController, 'function')
t.type(AbortSignal, 'function')

t.test('onabort method', t => {
  const ac = new AbortController()
  t.type(ac.signal, AbortSignal)

  let calledOnAbort = false
  ac.signal.onabort = () => (calledOnAbort = true)
  ac.abort()
  t.equal(calledOnAbort, true, 'called onabort method')

  t.end()
})

t.test('add/remove event listener', t => {
  const ac = new AbortController()
  let receivedEvent = null
  ac.signal.addEventListener('abort', e => (receivedEvent = e))
  const nope = () => {
    throw 'nope'
  }<commit_msg>note about why ac test is js<commit_after>// this is just a test of the AbortController polyfill
// which is a little bit weird, since that's not about lru caching
// at all, so it's tempting to think that this module should
// pull it in as a dep or something.  that would be the
// javascripty thing to do, right?  but it would mean that
// this is no longer a zero-deps module, so meh.  it's fine.
// This is a JS test rather than TS, because we have to do some
// improper things with types in order to make the polyfill load.
global.AbortController = null
global.AbortSignal = null

const t = require('tap')

const LRUCache = require('../')
const { AbortController, AbortSignal } = LRUCache

t.type(AbortController, 'function')
t.type(AbortSignal, 'function')

t.test('onabort method', t => {
  const ac = new AbortController()
  t.type(ac.signal, AbortSignal)

  let calledOnAbort = false
  ac.signal.onabort = () => (calledOnAbort = true)
  ac.abort()
  t.equal(calledOnAbort, true, 'called onabort method')

  t.end()
})

t.test('add/remove event listener', t => {
  const ac = new AbortController()
  let receivedEvent = null
  ac.signal.addEventListener('abort', e => (receivedEvent = e))
  const nope = () => {
    throw 'nope'
  }
{'fraction_non_alphanumeric': 0.1188542112013681, 'fraction_numerical': 0.0, 'mean_word_length': 3.7082494969818915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4977929', 'n_tokens_mistral': 769, 'n_tokens_neox': 747, 'n_words': 281}