|
| 1 | +import { spawnPromisified } from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import { describe, it } from 'node:test'; |
| 4 | +import { strictEqual, match, doesNotMatch } from 'node:assert'; |
| 5 | +import { Worker } from 'node:worker_threads'; |
| 6 | + |
| 7 | +const fixturePath = fixtures.path('disable-warnings.js'); |
| 8 | +const fixturePathWorker = fixtures.path('disable-warnings-worker.js'); |
| 9 | +const dep0025Message = /\(node:\d+\) \[DEP0025\] DeprecationWarning: sys is deprecated\. Use util instead\./; |
| 10 | +const dep0094Message = /\(node:\d+\) \[DEP0094\] DeprecationWarning: assert\.fail\(\) with more than one argument is deprecated\. Please use assert\.strictEqual\(\) instead or only pass a message\./; |
| 11 | +const experimentalWarningMessage = /\(node:\d+\) ExperimentalWarning: vm\.measureMemory is an experimental feature and might change at any time/; |
| 12 | + |
| 13 | +describe('process warnings', { concurrency: true }, () => { |
| 14 | + |
| 15 | + it('should emit all warnings by default', async () => { |
| 16 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 17 | + fixturePath, |
| 18 | + ]); |
| 19 | + |
| 20 | + strictEqual(stdout, ''); |
| 21 | + match(stderr, dep0025Message); |
| 22 | + match(stderr, dep0094Message); |
| 23 | + match(stderr, experimentalWarningMessage); |
| 24 | + strictEqual(code, 0); |
| 25 | + strictEqual(signal, null); |
| 26 | + }); |
| 27 | + |
| 28 | + describe('--no-warnings', { concurrency: true }, () => { |
| 29 | + it('should silence all warnings by default', async () => { |
| 30 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 31 | + '--no-warnings', |
| 32 | + fixturePath, |
| 33 | + ]); |
| 34 | + |
| 35 | + strictEqual(stdout, ''); |
| 36 | + doesNotMatch(stderr, dep0025Message); |
| 37 | + doesNotMatch(stderr, dep0094Message); |
| 38 | + doesNotMatch(stderr, experimentalWarningMessage); |
| 39 | + strictEqual(code, 0); |
| 40 | + strictEqual(signal, null); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('--no-deprecation', { concurrency: true }, () => { |
| 45 | + it('should silence all deprecation warnings', async () => { |
| 46 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 47 | + '--no-deprecation', |
| 48 | + fixturePath, |
| 49 | + ]); |
| 50 | + |
| 51 | + strictEqual(stdout, ''); |
| 52 | + doesNotMatch(stderr, dep0025Message); |
| 53 | + doesNotMatch(stderr, dep0094Message); |
| 54 | + match(stderr, experimentalWarningMessage); |
| 55 | + strictEqual(code, 0); |
| 56 | + strictEqual(signal, null); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('--disable-warnings', { concurrency: true }, () => { |
| 61 | + it('should silence deprecation warning DEP0025', async () => { |
| 62 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 63 | + '--disable-warnings=DEP0025', |
| 64 | + fixturePath, |
| 65 | + ]); |
| 66 | + |
| 67 | + strictEqual(stdout, ''); |
| 68 | + doesNotMatch(stderr, dep0025Message); |
| 69 | + match(stderr, dep0094Message); |
| 70 | + match(stderr, experimentalWarningMessage); |
| 71 | + strictEqual(code, 0); |
| 72 | + strictEqual(signal, null); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should silence deprecation warnings DEP0025 and DEP0094', async () => { |
| 76 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 77 | + '--disable-warnings=DEP0025', |
| 78 | + '--disable-warnings=DEP0094', |
| 79 | + fixturePath, |
| 80 | + ]); |
| 81 | + |
| 82 | + strictEqual(stdout, ''); |
| 83 | + doesNotMatch(stderr, dep0025Message); |
| 84 | + doesNotMatch(stderr, dep0094Message); |
| 85 | + match(stderr, experimentalWarningMessage); |
| 86 | + strictEqual(code, 0); |
| 87 | + strictEqual(signal, null); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should silence all deprecation warnings using type DeprecationWarning', async () => { |
| 91 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 92 | + '--disable-warnings=DeprecationWarning', |
| 93 | + fixturePath, |
| 94 | + ]); |
| 95 | + |
| 96 | + strictEqual(stdout, ''); |
| 97 | + doesNotMatch(stderr, dep0025Message); |
| 98 | + doesNotMatch(stderr, dep0094Message); |
| 99 | + match(stderr, experimentalWarningMessage); |
| 100 | + strictEqual(code, 0); |
| 101 | + strictEqual(signal, null); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should silence all experimental warnings using type ExperimentalWarning', async () => { |
| 105 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 106 | + '--disable-warnings=ExperimentalWarning', |
| 107 | + fixturePath, |
| 108 | + ]); |
| 109 | + |
| 110 | + strictEqual(stdout, ''); |
| 111 | + match(stderr, dep0025Message); |
| 112 | + match(stderr, dep0094Message); |
| 113 | + doesNotMatch(stderr, experimentalWarningMessage); |
| 114 | + strictEqual(code, 0); |
| 115 | + strictEqual(signal, null); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should pass down option to worker', async () => { |
| 119 | + const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ |
| 120 | + '--disable-warnings=DEP0094', |
| 121 | + fixturePathWorker, |
| 122 | + ]); |
| 123 | + |
| 124 | + strictEqual(stdout, ''); |
| 125 | + match(stderr, dep0025Message); |
| 126 | + doesNotMatch(stderr, dep0094Message); |
| 127 | + match(stderr, experimentalWarningMessage); |
| 128 | + strictEqual(code, 0); |
| 129 | + strictEqual(signal, null); |
| 130 | + }); |
| 131 | + }); |
| 132 | +}); |
0 commit comments