|
| 1 | +import { spawnPromisified } from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import { describe, it } from 'node:test'; |
| 4 | +import assert from 'node:assert'; |
| 5 | + |
| 6 | +const fixturePath = fixtures.path('disable-warning.js'); |
| 7 | +const fixturePathWorker = fixtures.path('disable-warning-worker.js'); |
| 8 | +const dep1Message = /\(node:\d+\) \[DEP1\] DeprecationWarning/; |
| 9 | +const dep2Message = /\(node:\d+\) \[DEP2\] DeprecationWarning/; |
| 10 | +const experimentalWarningMessage = /\(node:\d+\) ExperimentalWarning/; |
| 11 | + |
| 12 | +describe('process warnings', { concurrency: true }, () => { |
| 13 | + |
| 14 | + it('should emit all warnings by default', async () => { |
| 15 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 16 | + fixturePath, |
| 17 | + ]); |
| 18 | + |
| 19 | + assert.strictEqual(stdout, ''); |
| 20 | + assert.match(stderr, dep1Message); |
| 21 | + assert.match(stderr, dep2Message); |
| 22 | + assert.match(stderr, experimentalWarningMessage); |
| 23 | + assert.strictEqual(code, 0); |
| 24 | + assert.strictEqual(signal, null); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('--no-warnings', { concurrency: true }, () => { |
| 28 | + it('should silence all warnings by default', async () => { |
| 29 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 30 | + '--no-warnings', |
| 31 | + fixturePath, |
| 32 | + ]); |
| 33 | + |
| 34 | + assert.strictEqual(stdout, ''); |
| 35 | + assert.doesNotMatch(stderr, dep1Message); |
| 36 | + assert.doesNotMatch(stderr, dep2Message); |
| 37 | + assert.doesNotMatch(stderr, experimentalWarningMessage); |
| 38 | + assert.strictEqual(code, 0); |
| 39 | + assert.strictEqual(signal, null); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('--no-deprecation', { concurrency: true }, () => { |
| 44 | + it('should silence all deprecation warnings', async () => { |
| 45 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 46 | + '--no-deprecation', |
| 47 | + fixturePath, |
| 48 | + ]); |
| 49 | + |
| 50 | + assert.strictEqual(stdout, ''); |
| 51 | + assert.doesNotMatch(stderr, dep1Message); |
| 52 | + assert.doesNotMatch(stderr, dep2Message); |
| 53 | + assert.match(stderr, experimentalWarningMessage); |
| 54 | + assert.strictEqual(code, 0); |
| 55 | + assert.strictEqual(signal, null); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('--disable-warning', { concurrency: true }, () => { |
| 60 | + it('should silence deprecation warning DEP1', async () => { |
| 61 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 62 | + '--disable-warning=DEP1', |
| 63 | + fixturePath, |
| 64 | + ]); |
| 65 | + |
| 66 | + assert.strictEqual(stdout, ''); |
| 67 | + assert.doesNotMatch(stderr, dep1Message); |
| 68 | + assert.match(stderr, dep2Message); |
| 69 | + assert.match(stderr, experimentalWarningMessage); |
| 70 | + assert.strictEqual(code, 0); |
| 71 | + assert.strictEqual(signal, null); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should silence deprecation warnings DEP1 and DEP2', async () => { |
| 75 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 76 | + '--disable-warning=DEP1', |
| 77 | + '--disable-warning=DEP2', |
| 78 | + fixturePath, |
| 79 | + ]); |
| 80 | + |
| 81 | + assert.strictEqual(stdout, ''); |
| 82 | + assert.doesNotMatch(stderr, dep1Message); |
| 83 | + assert.doesNotMatch(stderr, dep2Message); |
| 84 | + assert.match(stderr, experimentalWarningMessage); |
| 85 | + assert.strictEqual(code, 0); |
| 86 | + assert.strictEqual(signal, null); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should silence all deprecation warnings using type DeprecationWarning', async () => { |
| 90 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 91 | + '--disable-warning=DeprecationWarning', |
| 92 | + fixturePath, |
| 93 | + ]); |
| 94 | + |
| 95 | + assert.strictEqual(stdout, ''); |
| 96 | + assert.doesNotMatch(stderr, dep1Message); |
| 97 | + assert.doesNotMatch(stderr, dep2Message); |
| 98 | + assert.match(stderr, experimentalWarningMessage); |
| 99 | + assert.strictEqual(code, 0); |
| 100 | + assert.strictEqual(signal, null); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should silence all experimental warnings using type ExperimentalWarning', async () => { |
| 104 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 105 | + '--disable-warning=ExperimentalWarning', |
| 106 | + fixturePath, |
| 107 | + ]); |
| 108 | + |
| 109 | + assert.strictEqual(stdout, ''); |
| 110 | + assert.match(stderr, dep1Message); |
| 111 | + assert.match(stderr, dep2Message); |
| 112 | + assert.doesNotMatch(stderr, experimentalWarningMessage); |
| 113 | + assert.strictEqual(code, 0); |
| 114 | + assert.strictEqual(signal, null); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should pass down option to worker', async () => { |
| 118 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 119 | + '--disable-warning=DEP2', |
| 120 | + fixturePathWorker, |
| 121 | + ]); |
| 122 | + |
| 123 | + assert.strictEqual(stdout, ''); |
| 124 | + assert.match(stderr, dep1Message); |
| 125 | + assert.doesNotMatch(stderr, dep2Message); |
| 126 | + assert.match(stderr, experimentalWarningMessage); |
| 127 | + assert.strictEqual(code, 0); |
| 128 | + assert.strictEqual(signal, null); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should not support a comma separated list', async () => { |
| 132 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 133 | + '--disable-warning=DEP1,DEP2', |
| 134 | + fixturePathWorker, |
| 135 | + ]); |
| 136 | + |
| 137 | + assert.strictEqual(stdout, ''); |
| 138 | + assert.match(stderr, dep1Message); |
| 139 | + assert.match(stderr, dep2Message); |
| 140 | + assert.match(stderr, experimentalWarningMessage); |
| 141 | + assert.strictEqual(code, 0); |
| 142 | + assert.strictEqual(signal, null); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should be specifiable in NODE_OPTIONS', async () => { |
| 146 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 147 | + fixturePath, |
| 148 | + ], { |
| 149 | + env: { |
| 150 | + ...process.env, |
| 151 | + NODE_OPTIONS: '--disable-warning=DEP2' |
| 152 | + } |
| 153 | + }); |
| 154 | + |
| 155 | + assert.strictEqual(stdout, ''); |
| 156 | + assert.match(stderr, dep1Message); |
| 157 | + assert.doesNotMatch(stderr, dep2Message); |
| 158 | + assert.match(stderr, experimentalWarningMessage); |
| 159 | + assert.strictEqual(code, 0); |
| 160 | + assert.strictEqual(signal, null); |
| 161 | + }); |
| 162 | + }); |
| 163 | +}); |
0 commit comments