mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52777 Changelog: [internal] This significantly speeds up test execution in Fantom (around 2x in OSS and 6x at Meta) by starting a Metro server before all tests runs and reusing it across all tests to build test bundles, instead of spinning up a new Metro instance every time we run each test. The architecture change (also considering the previous change in buck prebuilds) looks like this: {F1980689532} This is how is impacts execution times (compared to the baseline): * OSS * Before: 62s {F1980564286} * After: 30s (**2x faster**) {F1980564265} Reviewed By: andrewdacenko Differential Revision: D78741903 fbshipit-source-id: b209f88925e49cc2a2067e8df9b7fa9a29b4c8d2
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import {isOSS, validateEnvironmentVariables} from '../EnvironmentOptions';
|
|
import build from './build';
|
|
import Metro from 'metro';
|
|
import path from 'path';
|
|
|
|
export default async function globalSetup(
|
|
globalConfig: {...},
|
|
projectConfig: {...},
|
|
): Promise<void> {
|
|
process.env.__FANTOM_RUN_ID__ ??= `run-${Date.now()}`;
|
|
|
|
validateEnvironmentVariables();
|
|
|
|
await startMetroServer();
|
|
|
|
if (!isOSS) {
|
|
await build();
|
|
}
|
|
}
|
|
|
|
async function startMetroServer() {
|
|
const metroConfig = await Metro.loadConfig({
|
|
config: path.resolve(__dirname, '..', '..', 'config', 'metro.config.js'),
|
|
});
|
|
|
|
// We need to reuse the same port across runs because can only set environment
|
|
// variables for workers in the first one.
|
|
// $FlowExpectedError[cannot-write]
|
|
metroConfig.server.port =
|
|
process.env.__FANTOM_METRO_PORT__ != null
|
|
? Number(process.env.__FANTOM_METRO_PORT__)
|
|
: // Any available port
|
|
0;
|
|
|
|
const server = await Metro.runServer(metroConfig, {
|
|
waitForBundler: true,
|
|
watch: true,
|
|
});
|
|
|
|
if (process.env.__FANTOM_METRO_PORT__ == null) {
|
|
process.env.__FANTOM_METRO_PORT__ = String(
|
|
server.httpServer.address().port,
|
|
);
|
|
}
|
|
|
|
// $FlowExpectedError[prop-missing]
|
|
globalThis.__METRO_SERVER__ = server;
|
|
}
|