emit-once-only.test.js 594 B

1234567891011121314151617181920212223242526
  1. 'use strict'
  2. const test = require('tap').test
  3. const build = require('..')
  4. test('emit should emit a given code only once', t => {
  5. t.plan(4)
  6. const { create, emit, emitted } = build()
  7. process.on('warning', onWarning)
  8. function onWarning (warning) {
  9. t.equal(warning.name, 'FastifyDeprecation')
  10. t.equal(warning.code, 'CODE')
  11. t.equal(warning.message, 'Hello world')
  12. t.ok(emitted.get('CODE'))
  13. }
  14. create('FastifyDeprecation', 'CODE', 'Hello world')
  15. emit('CODE')
  16. emit('CODE')
  17. setImmediate(() => {
  18. process.removeListener('warning', onWarning)
  19. t.end()
  20. })
  21. })