From a09e494596ed7447bb8aa21d9e335d98886a7ee3 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Tue, 3 Sep 2024 05:35:53 -0700 Subject: [PATCH] Inline requires: cleanup bailout test case Summary: Cleanup one of a set of tests intended to check that the input is *not* modified in this particular case. The standard way to do this is to use `snapshot: false`, which checks that input == output. This test used `snapshot: true` only because the input was not correctly formatted, so the output had whitespace differences. Allows for clearer grouping of bail-out tests as we introduce memoization later in the stack. Changelog: Internal Reviewed By: vzaidman Differential Revision: D62084971 fbshipit-source-id: 2c5d856cc3a7c64feb919c46093ceb2af8c7d42b --- .../inline-requires-plugin-test.js.snap | 25 ------------------- .../__tests__/inline-requires-plugin-test.js | 7 +++--- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/packages/metro-transform-plugins/src/__tests__/__snapshots__/inline-requires-plugin-test.js.snap b/packages/metro-transform-plugins/src/__tests__/__snapshots__/inline-requires-plugin-test.js.snap index 888eaf1bbd..63eef5195d 100644 --- a/packages/metro-transform-plugins/src/__tests__/__snapshots__/inline-requires-plugin-test.js.snap +++ b/packages/metro-transform-plugins/src/__tests__/__snapshots__/inline-requires-plugin-test.js.snap @@ -10,31 +10,6 @@ var foo = require(\\"foo\\"); " `; -exports[`inline-requires does not transform require calls if it is not needed: does not transform require calls if it is not needed 1`] = ` -" -function test () { - function require(condition) { - if (!condition) { - throw new Error('The condition is false'); - } - } - - require('test'); -} - - ↓ ↓ ↓ ↓ ↓ ↓ - -function test() { - function require(condition) { - if (!condition) { - throw new Error('The condition is false'); - } - } - require('test'); -} -" -`; - exports[`inline-requires ensures that the inlined require still points to the global require function even if local require is not called: ensures that the inlined require still points to the global require function even if local require is not called 1`] = ` " const foo = require('foo'); diff --git a/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js b/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js index b1cfb244fd..5c71a51a72 100644 --- a/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js +++ b/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js @@ -146,19 +146,18 @@ pluginTester({ snapshot: false, }, - 'does not transform require calls if it is not needed': { + 'does not transform require calls that are already inline': { code: ` - function test () { + function test() { function require(condition) { if (!condition) { throw new Error('The condition is false'); } } - require('test'); } `, - snapshot: true, + snapshot: false, }, 'inlines requires that are referenced before the require statement': {