wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'
 
const test = require('tap').test
const build = require('..')
 
test('emit should emit a given code unlimited times', t => {
  t.plan(50)
 
  const { create, emit, emitted } = build()
 
  let runs = 0
  const expectedRun = []
  const times = 10
 
  process.on('warning', onWarning)
  function onWarning (warning) {
    t.equal(warning.name, 'FastifyDeprecation')
    t.equal(warning.code, 'CODE')
    t.equal(warning.message, 'Hello world')
    t.ok(emitted.get('CODE'))
    t.equal(runs++, expectedRun.shift())
  }
 
  create('FastifyDeprecation', 'CODE', 'Hello world', { unlimited: true })
 
  for (let i = 0; i < times; i++) {
    expectedRun.push(i)
    emit('CODE')
  }
  setImmediate(() => {
    process.removeListener('warning', onWarning)
    t.end()
  })
})