Skip to content

Commit

Permalink
Tests: silence expected console.warn in require-test output
Browse files Browse the repository at this point in the history
Summary:
Metro's `require` polyfill is expected to print require cycle warnings, and when testing cycle scenarios this spams the Jest output (except in the one case where we explicitly mock `console.warn` to check the warning).

This diff lifts the `console.warn` spy up so as to silence it.

Changelog: Internal

Reviewed By: jacdebug

Differential Revision: D44505719

fbshipit-source-id: 9ca845aa218d49896dcc2ec4723b403513302d80
  • Loading branch information
robhogan authored and facebook-github-bot committed Apr 5, 2023
1 parent 61a30b7 commit 88fb8fb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/metro-runtime/src/polyfills/__tests__/require-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function createModule(
);
}

const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});

describe('require', () => {
const moduleSystemCode = (() => {
const rawCode = fs.readFileSync(require.resolve('../require'), 'utf8');
Expand Down Expand Up @@ -85,6 +87,7 @@ describe('require', () => {

beforeEach(() => {
moduleSystem = {};
consoleWarnSpy.mockClear();
});

it('does not need any babel helper logic', () => {
Expand Down Expand Up @@ -567,15 +570,10 @@ describe('require', () => {
},
);

const warn = console.warn;
console.warn = jest.fn();

expect(moduleSystem.__r('foo.js')).toEqual('Hi!');
expect(console.warn).toHaveBeenCalledWith(
expect(consoleWarnSpy).toHaveBeenCalledWith(
'Requiring module "foo.js" by name is only supported for debugging purposes and will BREAK IN PRODUCTION!',
);

console.warn = warn;
});

it('throws an error when requiring an incorrect verboseNames in dev mode', () => {
Expand Down

0 comments on commit 88fb8fb

Please sign in to comment.