First commit
This commit is contained in:
26
node_modules/process-warning/test/emit-interpolated-string.test.js
generated
vendored
Normal file
26
node_modules/process-warning/test/emit-interpolated-string.test.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tap').test
|
||||
const build = require('..')
|
||||
|
||||
test('emit with interpolated string', t => {
|
||||
t.plan(4)
|
||||
const { create, emit, emitted } = build()
|
||||
|
||||
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'))
|
||||
}
|
||||
|
||||
create('FastifyDeprecation', 'CODE', 'Hello %s')
|
||||
emit('CODE', 'world')
|
||||
emit('CODE', 'world')
|
||||
|
||||
setImmediate(() => {
|
||||
process.removeListener('warning', onWarning)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
26
node_modules/process-warning/test/emit-once-only.test.js
generated
vendored
Normal file
26
node_modules/process-warning/test/emit-once-only.test.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tap').test
|
||||
const build = require('..')
|
||||
|
||||
test('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.equal(warning.name, 'FastifyDeprecation')
|
||||
t.equal(warning.code, 'CODE')
|
||||
t.equal(warning.message, 'Hello world')
|
||||
t.ok(emitted.get('CODE'))
|
||||
}
|
||||
|
||||
create('FastifyDeprecation', 'CODE', 'Hello world')
|
||||
emit('CODE')
|
||||
emit('CODE')
|
||||
setImmediate(() => {
|
||||
process.removeListener('warning', onWarning)
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
34
node_modules/process-warning/test/emit-unlimited.test.js
generated
vendored
Normal file
34
node_modules/process-warning/test/emit-unlimited.test.js
generated
vendored
Normal file
@ -0,0 +1,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()
|
||||
})
|
||||
})
|
||||
110
node_modules/process-warning/test/index.test.js
generated
vendored
Normal file
110
node_modules/process-warning/test/index.test.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tap').test
|
||||
const build = require('..')
|
||||
|
||||
process.removeAllListeners('warning')
|
||||
|
||||
test('Create warning with zero parameter', t => {
|
||||
t.plan(3)
|
||||
|
||||
const { create } = build()
|
||||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'Not available')
|
||||
const opts = buildWarnOpts()
|
||||
t.equal(opts.name, 'FastifyWarning')
|
||||
t.equal(opts.message, 'Not available')
|
||||
t.equal(opts.code, 'CODE')
|
||||
})
|
||||
|
||||
test('Create error with 1 parameter', t => {
|
||||
t.plan(3)
|
||||
|
||||
const { create } = build()
|
||||
const buildWarningOpts = create('FastifyWarning', 'CODE', 'hey %s')
|
||||
const opts = buildWarningOpts('alice')
|
||||
t.equal(opts.name, 'FastifyWarning')
|
||||
t.equal(opts.message, 'hey alice')
|
||||
t.equal(opts.code, 'CODE')
|
||||
})
|
||||
|
||||
test('Create error with 2 parameters', t => {
|
||||
t.plan(3)
|
||||
|
||||
const { create } = build()
|
||||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s')
|
||||
const opts = buildWarnOpts('alice', 'attitude')
|
||||
t.equal(opts.name, 'FastifyWarning')
|
||||
t.equal(opts.message, 'hey alice, I like your attitude')
|
||||
t.equal(opts.code, 'CODE')
|
||||
})
|
||||
|
||||
test('Create error with 3 parameters', t => {
|
||||
t.plan(3)
|
||||
|
||||
const { create } = build()
|
||||
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s %s')
|
||||
const opts = buildWarnOpts('alice', 'attitude', 'see you')
|
||||
t.equal(opts.name, 'FastifyWarning')
|
||||
t.equal(opts.message, 'hey alice, I like your attitude see you')
|
||||
t.equal(opts.code, 'CODE')
|
||||
})
|
||||
|
||||
test('Creates a deprecation warning', t => {
|
||||
t.plan(3)
|
||||
|
||||
const manager = build()
|
||||
const builder = manager.createDeprecation('CODE', 'hello %s')
|
||||
const warning = builder('world')
|
||||
t.equal(warning.name, 'DeprecationWarning')
|
||||
t.equal(warning.message, 'hello world')
|
||||
t.equal(warning.code, 'CODE')
|
||||
})
|
||||
|
||||
test('Should throw when error code has no fastify name', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { create } = build()
|
||||
|
||||
t.throws(() => create(), new Error('Warning name must not be empty'))
|
||||
})
|
||||
|
||||
test('Should throw when error has no code', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { create } = build()
|
||||
|
||||
t.throws(() => create('name'), new Error('Warning code must not be empty'))
|
||||
})
|
||||
|
||||
test('Should throw when error has no message', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { create } = build()
|
||||
|
||||
t.throws(() => create('name', 'code'), new Error('Warning message must not be empty'))
|
||||
})
|
||||
|
||||
test('Should throw if emit is called with unknown code ', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { emit } = build()
|
||||
|
||||
t.throws(() => emit('CODE'), new Error('The code \'CODE\' does not exist'))
|
||||
})
|
||||
|
||||
test('Cannot reuse the same code more than once', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { create } = build()
|
||||
create('FastifyWarning', 'CODE', 'Not available')
|
||||
|
||||
t.throws(() => create('FastifyWarning', 'CODE', 'Not available'), new Error("The code 'CODE' already exist"))
|
||||
})
|
||||
|
||||
test('Cannot set unlimited other than boolean', t => {
|
||||
t.plan(1)
|
||||
|
||||
const { create } = build()
|
||||
|
||||
t.throws(() => create('FastifyWarning', 'CODE', 'Msg', { unlimited: 42 }), new Error('Warning opts.unlimited must be a boolean'))
|
||||
})
|
||||
20
node_modules/process-warning/test/jest.test.js
generated
vendored
Normal file
20
node_modules/process-warning/test/jest.test.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/* global test, expect */
|
||||
'use strict'
|
||||
|
||||
const build = require('..')
|
||||
|
||||
test('works with jest', done => {
|
||||
const { create, emit, emitted } = build()
|
||||
|
||||
create('FastifyDeprecation', 'CODE', 'Hello %s')
|
||||
emit('CODE', 'world')
|
||||
|
||||
// we cannot actually listen to process warning event
|
||||
// because jest messes with it (that's the point of this test)
|
||||
// we can only test it was emitted indirectly
|
||||
// and test no exception is raised
|
||||
setImmediate(() => {
|
||||
expect(emitted.get('CODE')).toBeTruthy()
|
||||
done()
|
||||
})
|
||||
})
|
||||
80
node_modules/process-warning/test/no-warnings.test.js
generated
vendored
Normal file
80
node_modules/process-warning/test/no-warnings.test.js
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const { spawnSync } = require('child_process')
|
||||
const { resolve } = require('path')
|
||||
|
||||
const entry = resolve(__dirname, '../examples', 'example.js')
|
||||
|
||||
test('--no-warnings is set in cli', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
'--no-warnings',
|
||||
entry
|
||||
])
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.equal(stderr, '')
|
||||
})
|
||||
|
||||
test('--no-warnings is not set in cli', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
entry
|
||||
])
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
|
||||
})
|
||||
|
||||
test('NODE_NO_WARNINGS is set to 1', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
entry
|
||||
], {
|
||||
env: {
|
||||
NODE_NO_WARNINGS: '1'
|
||||
}
|
||||
})
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.equal(stderr, '')
|
||||
})
|
||||
|
||||
test('NODE_NO_WARNINGS is set to 0', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
entry
|
||||
], {
|
||||
env: {
|
||||
NODE_NO_WARNINGS: '0'
|
||||
}
|
||||
})
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
|
||||
})
|
||||
|
||||
test('NODE_NO_WARNINGS is not set', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
entry
|
||||
])
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
|
||||
})
|
||||
|
||||
test('NODE_Options contains --no-warnings', t => {
|
||||
t.plan(1)
|
||||
const child = spawnSync(process.execPath, [
|
||||
entry
|
||||
], {
|
||||
env: {
|
||||
NODE_OPTIONS: '--no-warnings'
|
||||
}
|
||||
})
|
||||
|
||||
const stderr = child.stderr.toString()
|
||||
t.equal(stderr, '')
|
||||
})
|
||||
Reference in New Issue
Block a user