Skip to content

Commit

Permalink
test: helper to expect deprecation warnings (electron#39405)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored and MrHuangJser committed Dec 11, 2023
1 parent 65866a0 commit 9add62b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/lib/deprecate-helpers.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 9add62b

Please sign in to comment.