From f33e3714a44c748175f48bcc7f2fb86f477ebfdf Mon Sep 17 00:00:00 2001 From: Yacine Hmito Date: Sun, 8 Dec 2019 12:40:27 +0100 Subject: [PATCH] use displayName instead of name --- docs/CLI.md | 2 +- e2e/run-projects/package.json | 7 +++-- packages/jest-core/src/cli/index.ts | 5 ++-- .../src/getConfigsOfProjectsToRun.ts | 8 ++++-- .../jest-core/src/getProjectDisplayName.ts | 24 +++++++++++++++++ .../src/getProjectsRunningMessage.ts | 26 ++++++++++++------- 6 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 packages/jest-core/src/getProjectDisplayName.ts diff --git a/docs/CLI.md b/docs/CLI.md index cffcea47253a..9eb9e464b791 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -250,7 +250,7 @@ Alias: `-i`. Run all tests serially in the current process, rather than creating ### `--runProjects ... ` -Run only the tests of the specified projects. Jest uses the attribute `name` in the configuration to identify each project. +Run only the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. ### `--runTestsByPath` diff --git a/e2e/run-projects/package.json b/e2e/run-projects/package.json index c6aeb31cbda5..564c775b7cac 100644 --- a/e2e/run-projects/package.json +++ b/e2e/run-projects/package.json @@ -2,14 +2,17 @@ "jest": { "projects": [ { - "name": "first-project", + "displayName": "first-project", "testMatch": [ "/__tests__/first-project.test.js" ], "testEnvironment": "node" }, { - "name": "second-project", + "displayName": { + "name": "second-project", + "color": "blue" + }, "testMatch": [ "/__tests__/second-project.test.js" ], diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index cbb90a432eb5..4d15ea15e6d6 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -76,8 +76,9 @@ export const runCLI = async ( const configsOfProjectsToRun = getConfigsOfProjectsToRun(argv, configs); if (argv.runProjects) { - const projectNames = configsOfProjectsToRun.map(config => config.name); - outputStream.write(getProjectsRunningMessage(projectNames) + '\n'); + outputStream.write( + getProjectsRunningMessage(configsOfProjectsToRun) + '\n', + ); } await _run( diff --git a/packages/jest-core/src/getConfigsOfProjectsToRun.ts b/packages/jest-core/src/getConfigsOfProjectsToRun.ts index f396d17720d2..977ed2a9357a 100644 --- a/packages/jest-core/src/getConfigsOfProjectsToRun.ts +++ b/packages/jest-core/src/getConfigsOfProjectsToRun.ts @@ -6,6 +6,7 @@ */ import {Config} from '@jest/types'; +import getProjectDisplayName from './getProjectDisplayName'; export default function getConfigsOfProjectsToRun( argv: Config.Argv, @@ -14,6 +15,9 @@ export default function getConfigsOfProjectsToRun( if (!argv.runProjects) { return projectConfigs; } - const namesOfProjectsToRun = new Set(argv.runProjects); - return projectConfigs.filter(config => namesOfProjectsToRun.has(config.name)); + const namesOfProjectsToRun = new Set(argv.runProjects); + return projectConfigs.filter(config => { + const name = getProjectDisplayName(config); + return name && namesOfProjectsToRun.has(name); + }); } diff --git a/packages/jest-core/src/getProjectDisplayName.ts b/packages/jest-core/src/getProjectDisplayName.ts new file mode 100644 index 000000000000..301b331021b8 --- /dev/null +++ b/packages/jest-core/src/getProjectDisplayName.ts @@ -0,0 +1,24 @@ +import {Config} from '@jest/types'; + +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export default function getProjectDisplayName( + projectConfig: Config.ProjectConfig, +): string | undefined { + const {displayName} = projectConfig; + if (!displayName) { + return undefined; + } + if (typeof displayName === 'string') { + return displayName; + } + if (typeof displayName === 'object') { + return displayName.name; + } + return undefined; +} diff --git a/packages/jest-core/src/getProjectsRunningMessage.ts b/packages/jest-core/src/getProjectsRunningMessage.ts index 2b39f1d26134..da923424e00c 100644 --- a/packages/jest-core/src/getProjectsRunningMessage.ts +++ b/packages/jest-core/src/getProjectsRunningMessage.ts @@ -1,3 +1,6 @@ +import {Config} from '@jest/types'; +import getProjectDisplayName from './getProjectDisplayName'; + /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * @@ -6,21 +9,26 @@ */ export default function getProjectsRunningMessage( - projectNames: Array, + projectConfigs: Array, ): string { - if (projectNames.length === 0) { + if (projectConfigs.length === 0) { return 'No project to run'; } - if (projectNames.length === 1) { - return `Will run one project: ${projectNames[0]}`; + if (projectConfigs.length === 1) { + const name = getProjectDisplayName(projectConfigs[0]); + return `Will run one project: ${name}`; } - const projectsList = projectNames - .map(getListElement) + const projectsList = projectConfigs + .map(getProjectNameListElement) .sort() .join('\n'); - return `Will run ${projectNames.length} projects:\n` + projectsList; + return `Will run ${projectConfigs.length} projects:\n` + projectsList; } -function getListElement(content: string): string { - return `- ${content}`; +function getProjectNameListElement( + projectConfig: Config.ProjectConfig, +): string { + const name = getProjectDisplayName(projectConfig); + const elementContent = name || ''; + return `- ${elementContent}`; }