This commit is contained in:
nik
2025-10-03 22:27:28 +03:00
parent 829fad0e17
commit 871cf7e792
16520 changed files with 2967597 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
'use strict'
const test = require('tap').test
const { createWarning } = require('..')
test('emit with interpolated string', t => {
t.plan(4)
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'TestDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(codeWarning.emitted)
}
const codeWarning = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello %s'
})
codeWarning('world')
codeWarning('world')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

View File

@@ -0,0 +1,28 @@
'use strict'
const test = require('tap').test
const { createWarning } = require('..')
test('emit should emit a given code only once', t => {
t.plan(4)
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'TestDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(warn.emitted)
}
const warn = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello world'
})
warn()
warn()
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

36
node_modules/process-warning/test/emit-reset.test.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
'use strict'
const test = require('tap').test
const { createWarning } = require('../')
test('a limited warning can be re-set', t => {
t.plan(4)
let count = 0
process.on('warning', onWarning)
function onWarning () {
count++
}
const warn = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello world'
})
warn()
t.ok(warn.emitted)
warn()
t.ok(warn.emitted)
warn.emitted = false
warn()
t.ok(warn.emitted)
setImmediate(() => {
t.equal(count, 2)
process.removeListener('warning', onWarning)
t.end()
})
})

30
node_modules/process-warning/test/emit-set.test.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
'use strict'
const test = require('tap').test
const { createWarning } = require('../')
test('emit should set the emitted state', t => {
t.plan(3)
process.on('warning', onWarning)
function onWarning () {
t.fail('should not be called')
}
const warn = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello world'
})
t.notOk(warn.emitted)
warn.emitted = true
t.ok(warn.emitted)
warn()
t.ok(warn.emitted)
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

View File

@@ -0,0 +1,37 @@
'use strict'
const test = require('tap').test
const { createWarning } = require('..')
test('emit should emit a given code unlimited times', t => {
t.plan(50)
let runs = 0
const expectedRun = []
const times = 10
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'TestDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(warn.emitted)
t.equal(runs++, expectedRun.shift())
}
const warn = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello world',
unlimited: true
})
for (let i = 0; i < times; i++) {
expectedRun.push(i)
warn()
}
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

99
node_modules/process-warning/test/index.test.js generated vendored Normal file
View File

@@ -0,0 +1,99 @@
'use strict'
const test = require('tap').test
const { createWarning, createDeprecation } = require('..')
process.removeAllListeners('warning')
test('Create warning with zero parameter', t => {
t.plan(3)
const warnItem = createWarning({
name: 'TestWarning',
code: 'CODE',
message: 'Not available'
})
t.equal(warnItem.name, 'TestWarning')
t.equal(warnItem.message, 'Not available')
t.equal(warnItem.code, 'CODE')
})
test('Create error with 1 parameter', t => {
t.plan(3)
const warnItem = createWarning({
name: 'TestWarning',
code: 'CODE',
message: 'hey %s'
})
t.equal(warnItem.name, 'TestWarning')
t.equal(warnItem.format('alice'), 'hey alice')
t.equal(warnItem.code, 'CODE')
})
test('Create error with 2 parameters', t => {
t.plan(3)
const warnItem = createWarning({
name: 'TestWarning',
code: 'CODE',
message: 'hey %s, I like your %s'
})
t.equal(warnItem.name, 'TestWarning')
t.equal(warnItem.format('alice', 'attitude'), 'hey alice, I like your attitude')
t.equal(warnItem.code, 'CODE')
})
test('Create error with 3 parameters', t => {
t.plan(3)
const warnItem = createWarning({
name: 'TestWarning',
code: 'CODE',
message: 'hey %s, I like your %s %s'
})
t.equal(warnItem.name, 'TestWarning')
t.equal(warnItem.format('alice', 'attitude', 'see you'), 'hey alice, I like your attitude see you')
t.equal(warnItem.code, 'CODE')
})
test('Creates a deprecation warning', t => {
t.plan(3)
const deprecationItem = createDeprecation({
name: 'DeprecationWarning',
code: 'CODE',
message: 'hello %s'
})
t.equal(deprecationItem.name, 'DeprecationWarning')
t.equal(deprecationItem.format('world'), 'hello world')
t.equal(deprecationItem.code, 'CODE')
})
test('Should throw when error code has no name', t => {
t.plan(1)
t.throws(() => createWarning(), new Error('Warning name must not be empty'))
})
test('Should throw when error has no code', t => {
t.plan(1)
t.throws(() => createWarning({ name: 'name' }), new Error('Warning code must not be empty'))
})
test('Should throw when error has no message', t => {
t.plan(1)
t.throws(() => createWarning({
name: 'name',
code: 'code'
}), new Error('Warning message must not be empty'))
})
test('Cannot set unlimited other than boolean', t => {
t.plan(1)
t.throws(() => createWarning({
name: 'name',
code: 'code',
message: 'message',
unlimited: 'unlimited'
}), new Error('Warning opts.unlimited must be a boolean'))
})

33
node_modules/process-warning/test/issue-88.test.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
'use strict'
const { test } = require('tap')
const { createWarning } = require('..')
test('Must not overwrite config', t => {
t.plan(1)
function onWarning (warning) {
t.equal(warning.code, 'CODE_1')
}
const a = createWarning({
name: 'TestWarning',
code: 'CODE_1',
message: 'Msg'
})
createWarning({
name: 'TestWarning',
code: 'CODE_2',
message: 'Msg',
unlimited: true
})
process.on('warning', onWarning)
a('CODE_1')
a('CODE_1')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

22
node_modules/process-warning/test/jest.test.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/* global test, expect */
'use strict'
const { createWarning } = require('..')
test('works with jest', done => {
const code = createWarning({
name: 'TestDeprecation',
code: 'CODE',
message: 'Hello world'
})
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(code.emitted).toBeTruthy()
done()
})
})

80
node_modules/process-warning/test/no-warnings.test.js generated vendored Normal file
View 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, '')
})