-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Geoffrey Booth <[email protected]> Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #50661 Fixes: #30810 Fixes: #47478 Fixes: #46862 Fixes: #40940 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Richard Lau <[email protected]>
- Loading branch information
Showing
7 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
const path = require('node:path'); | ||
const { Worker } = require('node:worker_threads'); | ||
new Worker(path.join(__dirname, './disable-warning.js')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
process.emitWarning('Deprecation Warning 1', { | ||
code: 'DEP1', | ||
type: 'DeprecationWarning' | ||
}); | ||
|
||
process.emitWarning('Deprecation Warning 2', { | ||
code: 'DEP2', | ||
type: 'DeprecationWarning' | ||
}); | ||
|
||
process.emitWarning('Experimental Warning', { | ||
type: 'ExperimentalWarning' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
const fixturePath = fixtures.path('disable-warning.js'); | ||
const fixturePathWorker = fixtures.path('disable-warning-worker.js'); | ||
const dep1Message = /\(node:\d+\) \[DEP1\] DeprecationWarning/; | ||
const dep2Message = /\(node:\d+\) \[DEP2\] DeprecationWarning/; | ||
const experimentalWarningMessage = /\(node:\d+\) ExperimentalWarning/; | ||
|
||
describe('process warnings', { concurrency: true }, () => { | ||
|
||
it('should emit all warnings by default', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, dep1Message); | ||
assert.match(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
describe('--no-warnings', { concurrency: true }, () => { | ||
it('should silence all warnings by default', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--no-warnings', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.doesNotMatch(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.doesNotMatch(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
}); | ||
|
||
describe('--no-deprecation', { concurrency: true }, () => { | ||
it('should silence all deprecation warnings', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--no-deprecation', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.doesNotMatch(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
}); | ||
|
||
describe('--disable-warning', { concurrency: true }, () => { | ||
it('should silence deprecation warning DEP1', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=DEP1', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.doesNotMatch(stderr, dep1Message); | ||
assert.match(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should silence deprecation warnings DEP1 and DEP2', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=DEP1', | ||
'--disable-warning=DEP2', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.doesNotMatch(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should silence all deprecation warnings using type DeprecationWarning', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=DeprecationWarning', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.doesNotMatch(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should silence all experimental warnings using type ExperimentalWarning', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=ExperimentalWarning', | ||
fixturePath, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, dep1Message); | ||
assert.match(stderr, dep2Message); | ||
assert.doesNotMatch(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should pass down option to worker', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=DEP2', | ||
fixturePathWorker, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should not support a comma separated list', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
'--disable-warning=DEP1,DEP2', | ||
fixturePathWorker, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, dep1Message); | ||
assert.match(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should be specifiable in NODE_OPTIONS', async () => { | ||
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [ | ||
fixturePath, | ||
], { | ||
env: { | ||
...process.env, | ||
NODE_OPTIONS: '--disable-warning=DEP2' | ||
} | ||
}); | ||
|
||
assert.strictEqual(stdout, ''); | ||
assert.match(stderr, dep1Message); | ||
assert.doesNotMatch(stderr, dep2Message); | ||
assert.match(stderr, experimentalWarningMessage); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
}); | ||
}); |