Fix stateful regex bug in benchmark detection (#56423)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56423

Changelog: [Internal]

The `FANTOM_BENCHMARK_FILENAME_RE` and `FANTOM_BENCHMARK_SUITE_RE` regexes used the `g` (global) flag, which makes `.test()` stateful — it preserves `lastIndex` between calls. When `getFantomTestConfigs` is called for multiple test files in the same process, the stale `lastIndex` from a previous successful match causes `.test()` to miss the match on the next file, returning `false`. This results in benchmark files intermittently getting the default dev config (`isJsOptimized: false`, `dev: true`), causing them to fail at runtime with "Benchmarks should not be run in development mode".

Removes the `g` flag from both regexes since they are used with `.test()` across different strings and should be stateless.

___

overriding_review_checks_triggers_an_audit_and_retroactive_review
Oncall Short Name: react_native_iroc

Differential Revision: D100603612

fbshipit-source-id: 4eded9b0a59a2343ad44c0c1c2855466e3981b7a
This commit is contained in:
Rubén Norte
2026-04-13 04:31:04 -07:00
committed by meta-codesync[bot]
parent a8b39a237c
commit 4bdfaf222b
+2 -2
View File
@@ -72,9 +72,9 @@ export const DEFAULT_FEATURE_FLAGS: FantomTestConfigFeatureFlags = {
const FANTOM_FLAG_FORMAT = /^(\w+):((?:\w+)|\*)$/;
const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./g;
const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./;
const FANTOM_BENCHMARK_SUITE_RE =
/\n(Fantom\.)?unstable_benchmark(\s*)\.suite\(/g;
/\n(Fantom\.)?unstable_benchmark(\s*)\.suite\(/;
const MAX_FANTOM_CONFIGURATION_VARIATIONS = 12;