diff --git a/packages/jest-cli/src/cli/index.ts b/packages/jest-cli/src/cli/index.ts index 96d817616ae8..c4024ea7aab1 100644 --- a/packages/jest-cli/src/cli/index.ts +++ b/packages/jest-cli/src/cli/index.ts @@ -28,16 +28,9 @@ export async function run(maybeArgv?: Array, project?: Config.Path) { return; } - const {isGlobalProject, projects} = getProjectListFromCLIArgs( - argv, - project, - ); - - const {results, globalConfig} = await runCLI( - argv, - projects, - isGlobalProject, - ); + const projects = getProjectListFromCLIArgs(argv, project); + + const {results, globalConfig} = await runCLI(argv, projects); readResultsAndExit(results, globalConfig); } catch (error) { clearLine(process.stderr); @@ -90,7 +83,6 @@ const getProjectListFromCLIArgs = ( argv: Config.Argv, project?: Config.Path, ) => { - let isGlobalProject = false; const projects = argv.projects ? argv.projects : []; if (project) { @@ -100,7 +92,6 @@ const getProjectListFromCLIArgs = ( if (!projects.length && process.platform === 'win32') { try { projects.push(realpath(process.cwd())); - isGlobalProject = true; } catch (err) { // do nothing, just catch error // process.binding('fs').realpath can throw, e.g. on mapped drives @@ -108,11 +99,10 @@ const getProjectListFromCLIArgs = ( } if (!projects.length) { - isGlobalProject = true; projects.push(process.cwd()); } - return {isGlobalProject, projects}; + return projects; }; const readResultsAndExit = ( diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index 8b65985db130..38e4f5a8cee2 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -9,6 +9,7 @@ import * as fs from 'fs'; import * as path from 'path'; import {Config} from '@jest/types'; import chalk = require('chalk'); +import {sync as realpath} from 'realpath-native'; import {isJSONString, replaceRootDirInPath} from './utils'; import normalize from './normalize'; import resolveConfigPath from './resolveConfigPath'; @@ -263,7 +264,6 @@ This usually means that your ${chalk.bold( export function readConfigs( argv: Config.Argv, projectPaths: Array, - isGlobalProject: boolean, ): { globalConfig: Config.GlobalConfig; configs: Array; @@ -308,10 +308,12 @@ export function readConfigs( return true; }) .map((root, projectIndex) => { - // Skip on all except: projectIndex === 0, and isGlobalProject, and projects.length === 1 + // Skip on all except: projectIndex === 0, projects[0] === process.cwd() or realpath(process.cwd()) on Windows, and projects.length === 1 const skipArgvConfigOption = !( projectIndex === 0 && - isGlobalProject && + (process.platform === 'win32' + ? projects[0] === realpath(process.cwd()) + : projects[0] === process.cwd()) && projects.length === 1 ); return readConfig( diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index 2a730bdd5d6b..ad2f2e2bea73 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -34,7 +34,6 @@ type OnCompleteCallback = (results: AggregatedResult) => void; export const runCLI = async ( argv: Config.Argv, projects: Array, - isGlobalProject: boolean, ): Promise<{ results: AggregatedResult; globalConfig: Config.GlobalConfig; @@ -53,7 +52,6 @@ export const runCLI = async ( const {globalConfig, configs, hasDeprecationWarnings} = readConfigs( argv, projects, - isGlobalProject, ); if (argv.debug) {