|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow strict-local |
| 8 | + * @format |
| 9 | + */ |
| 10 | + |
| 11 | +'use strict'; |
| 12 | + |
| 13 | +const path = require('node:path'); |
| 14 | + |
| 15 | +const PROJECT_ROOT = path.sep === '/' ? '/my/project' : 'C:\\my\\project'; |
| 16 | + |
| 17 | +// The transformer memoizes its resolved Babel config in a module-level |
| 18 | +// closure, so a fresh module instance is required for every distinct config. |
| 19 | +beforeEach(() => { |
| 20 | + jest.resetModules(); |
| 21 | +}); |
| 22 | + |
| 23 | +function getCallerSupportsInlineModules( |
| 24 | + supportsInlineModules: ?boolean, |
| 25 | +): unknown { |
| 26 | + const {transform} = require('../index.js'); |
| 27 | + let callerValue: unknown = null; |
| 28 | + transform({ |
| 29 | + filename: path.join(PROJECT_ROOT, 'App.js'), |
| 30 | + src: 'export const foo = 1;', |
| 31 | + plugins: [ |
| 32 | + api => { |
| 33 | + callerValue = api.caller(caller => caller?.supportsInlineModules); |
| 34 | + return {visitor: {}}; |
| 35 | + }, |
| 36 | + ], |
| 37 | + options: { |
| 38 | + ...(supportsInlineModules != null ? {supportsInlineModules} : null), |
| 39 | + dev: true, |
| 40 | + enableBabelRuntime: false, |
| 41 | + enableBabelRCLookup: false, |
| 42 | + globalPrefix: '__metro__', |
| 43 | + minify: false, |
| 44 | + platform: 'ios', |
| 45 | + publicPath: 'test', |
| 46 | + projectRoot: PROJECT_ROOT, |
| 47 | + }, |
| 48 | + }); |
| 49 | + return callerValue; |
| 50 | +} |
| 51 | + |
| 52 | +test.each([[true], [false], [undefined]])( |
| 53 | + 'passes supportsInlineModules: %s to Babel through the caller', |
| 54 | + supportsInlineModules => { |
| 55 | + expect(getCallerSupportsInlineModules(supportsInlineModules)).toBe( |
| 56 | + supportsInlineModules, |
| 57 | + ); |
| 58 | + }, |
| 59 | +); |
0 commit comments