Files
Andrew Datsenko 22002bb70c 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
2025-09-23 13:40:31 -07:00

36 lines
867 B
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
*/
// $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;
}