Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/fastify-warning/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const test = require('ava')
const build = require('./')
process.removeAllListeners('warning')
test('Create warning with zero parameter', t => {
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'Not available')
const opts = buildWarnOpts()
t.is(opts.name, 'FastifyWarning')
t.is(opts.message, 'Not available')
t.is(opts.code, 'CODE')
})
test('Create error with 1 parameter', t => {
const { create } = build()
const buildWarningOpts = create('FastifyWarning', 'CODE', 'hey %s')
const opts = buildWarningOpts('alice')
t.is(opts.name, 'FastifyWarning')
t.is(opts.message, 'hey alice')
t.is(opts.code, 'CODE')
})
test('Create error with 2 parameters', t => {
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s')
const opts = buildWarnOpts('alice', 'attitude')
t.is(opts.name, 'FastifyWarning')
t.is(opts.message, 'hey alice, I like your attitude')
t.is(opts.code, 'CODE')
})
test('Create error with 3 parameters', t => {
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s %s')
const opts = buildWarnOpts('alice', 'attitude', 'see you')
t.is(opts.name, 'FastifyWarning')
t.is(opts.message, 'hey alice, I like your attitude see you')
t.is(opts.code, 'CODE')
})
test('Should throw when error code has no fastify name', t => {
const { create } = build()
try {
create()
} catch (err) {
t.is(err.message, 'Fastify warning name must not be empty')
}
})
test('Should throw when error has no code', t => {
const { create } = build()
try {
create('name')
} catch (err) {
t.is(err.message, 'Fastify warning code must not be empty')
}
})
test('Should throw when error has no message', t => {
const { create } = build()
try {
create('name', 'code')
} catch (err) {
t.is(err.message, 'Fastify warning message must not be empty')
}
})
test.serial.cb('emit should emit a given code only once', t => {
t.plan(4)
const { create, emit, emitted } = build()
process.on('warning', onWarning)
function onWarning (warning) {
t.is(warning.name, 'FastifyDeprecation')
t.is(warning.code, 'CODE')
t.is(warning.message, 'Hello world')
t.true(emitted.get('CODE'))
}
create('FastifyDeprecation', 'CODE', 'Hello world')
emit('CODE')
emit('CODE')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})
test.serial.cb('emit with interpolated string', t => {
t.plan(4)
const { create, emit, emitted } = build()
process.on('warning', onWarning)
function onWarning (warning) {
t.is(warning.name, 'FastifyDeprecation')
t.is(warning.code, 'CODE')
t.is(warning.message, 'Hello world')
t.true(emitted.get('CODE'))
}
create('FastifyDeprecation', 'CODE', 'Hello %s')
emit('CODE', 'world')
emit('CODE', 'world')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})
test('Cannot reuse the same code more than once', t => {
const { create } = build()
create('FastifyWarning', 'CODE', 'Not available')
try {
create('FastifyWarning', 'CODE', 'Not available')
} catch (err) {
t.is(err.message, "The code 'CODE' already exist")
}
})
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.005 ]-- |