From acbdda3716a67f4977e995c8a509b91ccdf92609 Mon Sep 17 00:00:00 2001 From: MatteoH2O1999 Date: Sun, 23 Jul 2023 17:21:23 +0200 Subject: [PATCH] Move normalizeIcons function to @jest/test-utils --- e2e/Utils.ts | 13 ++----------- .../src/__tests__/GitHubActionsReporter.test.ts | 2 +- packages/test-utils/src/index.ts | 2 ++ packages/test-utils/src/normalizeIcons.ts | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 packages/test-utils/src/normalizeIcons.ts diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 3f0eaf20f4b1..1538ddcf542c 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -310,17 +310,6 @@ export const extractSummaries = ( .map(({start, end}) => extractSortedSummary(stdout.slice(start, end))); }; -export const normalizeIcons = (str: string) => { - if (!str) { - return str; - } - - // Make sure to keep in sync with `jest-util/src/specialChars` - return str - .replace(new RegExp('\u00D7', 'gu'), '\u2715') - .replace(new RegExp('\u221A', 'gu'), '\u2713'); -}; - // Certain environments (like CITGM and GH Actions) do not come with mercurial installed let hgIsInstalled: boolean | null = null; @@ -369,3 +358,5 @@ export const testIfSlAndHg = (...args: Parameters) => { test.skip(...args); } }; + +export {normalizeIcons} from '@jest/test-utils'; diff --git a/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts b/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts index e0ef8c1038bf..609b5697a5e4 100644 --- a/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts +++ b/packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts @@ -13,8 +13,8 @@ import type { TestCaseResult, TestResult, } from '@jest/test-result'; +import {normalizeIcons} from '@jest/test-utils'; import type {Config} from '@jest/types'; -import {normalizeIcons} from '../../../../e2e/Utils'; import BaseGitHubActionsReporter from '../GitHubActionsReporter'; afterEach(() => { diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index 982674483d24..efb9649a66c3 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts @@ -15,3 +15,5 @@ export { } from './ConditionalTest'; export {makeGlobalConfig, makeProjectConfig} from './config'; + +export {normalizeIcons} from './normalizeIcons'; diff --git a/packages/test-utils/src/normalizeIcons.ts b/packages/test-utils/src/normalizeIcons.ts new file mode 100644 index 000000000000..6c672384d642 --- /dev/null +++ b/packages/test-utils/src/normalizeIcons.ts @@ -0,0 +1,17 @@ +/** + * 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. + */ + +export function normalizeIcons(str: string): string { + if (!str) { + return str; + } + + // Make sure to keep in sync with `jest-util/src/specialChars` + return str + .replace(new RegExp('\u00D7', 'gu'), '\u2715') + .replace(new RegExp('\u221A', 'gu'), '\u2713'); +}