From 9497eff12ae089a2368cab01543d72faf324b32a 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 | 11 ----------- e2e/runJest.ts | 2 +- .../src/__tests__/GitHubActionsReporter.test.ts | 2 +- packages/test-utils/src/index.ts | 2 ++ packages/test-utils/src/normalizeIcons.ts | 17 +++++++++++++++++ 5 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 packages/test-utils/src/normalizeIcons.ts diff --git a/e2e/Utils.ts b/e2e/Utils.ts index 3f0eaf20f4b1..31757a49891c 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; diff --git a/e2e/runJest.ts b/e2e/runJest.ts index 8de50ea7f2ea..2d198657f7de 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -13,9 +13,9 @@ import execa = require('execa'); import * as fs from 'graceful-fs'; import stripAnsi = require('strip-ansi'); import type {FormattedTestResults} from '@jest/test-result'; +import {normalizeIcons} from '@jest/test-utils'; import type {Config} from '@jest/types'; import {ErrorWithStack} from 'jest-util'; -import {normalizeIcons} from './Utils'; const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js'); 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'); +}