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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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, '')
})