mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Allow to disable coverage via flag & disable it for benchmarks (#53912)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b00d3be572
commit
22002bb70c
@@ -5,6 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @fantom_mode *
|
||||
* @fantom_disable_coverage
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -147,6 +147,9 @@ Available pragmas:
|
||||
- Possible values:
|
||||
- `true`: using Hermes bytecode
|
||||
- `false`: not using Hermes bytecode
|
||||
- `@fantom_disable_coverage`: used to disable coverage collection for the test.
|
||||
- Example: `@fantom_disable_coverage`
|
||||
- Does not require a value.
|
||||
- `@fantom_react_fb_flags`: used to set overrides for internal React flags set
|
||||
in ReactNativeInternalFeatureFlags (Meta use only)
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
// $FlowExpectedError[untyped-import]
|
||||
import {extract, parse} from 'jest-docblock';
|
||||
|
||||
type DocblockPragmas = {[key: string]: string | string[]};
|
||||
|
||||
const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./g;
|
||||
|
||||
export function shouldCollectCoverage(
|
||||
testPath: string,
|
||||
testContents: string,
|
||||
globalConfig: {collectCoverage: boolean, ...},
|
||||
): boolean {
|
||||
if (FANTOM_BENCHMARK_FILENAME_RE.test(testPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const docblock = extract(testContents);
|
||||
const pragmas = parse(docblock) as DocblockPragmas;
|
||||
|
||||
if (pragmas.fantom_disable_coverage != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return globalConfig.collectCoverage;
|
||||
}
|
||||
@@ -85,6 +85,7 @@ const VALID_FANTOM_PRAGMAS = [
|
||||
'fantom_flags',
|
||||
'fantom_hermes_variant',
|
||||
'fantom_react_fb_flags',
|
||||
'fantom_disable_coverage',
|
||||
];
|
||||
|
||||
export function getOverrides(
|
||||
|
||||
+6
-1
@@ -24,6 +24,7 @@ import type {
|
||||
|
||||
import {printBenchmarkResultsRanking} from './benchmarkUtils';
|
||||
import {createBundle, createSourceMap} from './bundling';
|
||||
import {shouldCollectCoverage} from './coverageUtils';
|
||||
import entrypointTemplate from './entrypoint-template';
|
||||
import * as EnvironmentOptions from './EnvironmentOptions';
|
||||
import {run as runHermesCompiler} from './executables/hermesc';
|
||||
@@ -343,7 +344,11 @@ module.exports = async function runTest(
|
||||
sourceMap: true,
|
||||
sourceMapUrl: sourceMapPath,
|
||||
customTransformOptions: {
|
||||
collectCoverage: globalConfig.collectCoverage,
|
||||
collectCoverage: shouldCollectCoverage(
|
||||
testPath,
|
||||
testContents,
|
||||
globalConfig,
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user