Skip to content

Commit 22002bb

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Allow to disable coverage via flag & disable it for benchmarks (#53912)
Summary: Pull Request resolved: #53912 Changelog: [Internal] Add new fantom flag `fantom_disable_coverage` to be used in tests that are sensitive to things like memory allocation. Also disable coverage for any benchmark test. Reviewed By: arushikesarwani94 Differential Revision: D83070065 fbshipit-source-id: a885e79e3d0c88cfb7adef30cb60ab46a617edac
1 parent b00d3be commit 22002bb

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

packages/react-native/src/private/__tests__/MemoryBaseline-itest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @fantom_mode *
8+
* @fantom_disable_coverage
89
* @flow strict-local
910
* @format
1011
*/

private/react-native-fantom/__docs__/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Available pragmas:
147147
- Possible values:
148148
- `true`: using Hermes bytecode
149149
- `false`: not using Hermes bytecode
150+
- `@fantom_disable_coverage`: used to disable coverage collection for the test.
151+
- Example: `@fantom_disable_coverage`
152+
- Does not require a value.
150153
- `@fantom_react_fb_flags`: used to set overrides for internal React flags set
151154
in ReactNativeInternalFeatureFlags (Meta use only)
152155

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// $FlowExpectedError[untyped-import]
12+
import {extract, parse} from 'jest-docblock';
13+
14+
type DocblockPragmas = {[key: string]: string | string[]};
15+
16+
const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./g;
17+
18+
export function shouldCollectCoverage(
19+
testPath: string,
20+
testContents: string,
21+
globalConfig: {collectCoverage: boolean, ...},
22+
): boolean {
23+
if (FANTOM_BENCHMARK_FILENAME_RE.test(testPath)) {
24+
return false;
25+
}
26+
27+
const docblock = extract(testContents);
28+
const pragmas = parse(docblock) as DocblockPragmas;
29+
30+
if (pragmas.fantom_disable_coverage != null) {
31+
return false;
32+
}
33+
34+
return globalConfig.collectCoverage;
35+
}

private/react-native-fantom/runner/getFantomTestConfigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const VALID_FANTOM_PRAGMAS = [
8585
'fantom_flags',
8686
'fantom_hermes_variant',
8787
'fantom_react_fb_flags',
88+
'fantom_disable_coverage',
8889
];
8990

9091
export function getOverrides(

private/react-native-fantom/runner/runner.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424

2525
import {printBenchmarkResultsRanking} from './benchmarkUtils';
2626
import {createBundle, createSourceMap} from './bundling';
27+
import {shouldCollectCoverage} from './coverageUtils';
2728
import entrypointTemplate from './entrypoint-template';
2829
import * as EnvironmentOptions from './EnvironmentOptions';
2930
import {run as runHermesCompiler} from './executables/hermesc';
@@ -343,7 +344,11 @@ module.exports = async function runTest(
343344
sourceMap: true,
344345
sourceMapUrl: sourceMapPath,
345346
customTransformOptions: {
346-
collectCoverage: globalConfig.collectCoverage,
347+
collectCoverage: shouldCollectCoverage(
348+
testPath,
349+
testContents,
350+
globalConfig,
351+
),
347352
},
348353
};
349354

0 commit comments

Comments
 (0)