test: helper to expect deprecation warnings (#39405)
This commit is contained in:
parent
d24d8f1f78
commit
0425454687
1 changed files with 26 additions and 0 deletions
26
spec/lib/deprecate-helpers.ts
Normal file
26
spec/lib/deprecate-helpers.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
export async function expectDeprecationMessages (func: () => any, ...expected: string[]) {
|
||||||
|
const messages: string[] = [];
|
||||||
|
|
||||||
|
const originalWarn = console.warn;
|
||||||
|
console.warn = (message) => {
|
||||||
|
messages.push(message);
|
||||||
|
};
|
||||||
|
|
||||||
|
const warningListener = (error: Error) => {
|
||||||
|
messages.push(error.message);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('warning', warningListener);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await func();
|
||||||
|
} finally {
|
||||||
|
// process.emitWarning seems to need us to wait a tick
|
||||||
|
await new Promise(process.nextTick);
|
||||||
|
console.warn = originalWarn;
|
||||||
|
process.off('warning', warningListener);
|
||||||
|
expect(messages).to.deep.equal(expected);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue