Skip to content
/ jest Public
forked from jestjs/jest

Commit ec539a0

Browse files
committed
fix(jest-cli): use import-local to support global Jest installations
Fixes jestjs#5294
1 parent 09e47d6 commit ec539a0

File tree

6 files changed

+46
-65
lines changed

6 files changed

+46
-65
lines changed

CHANGELOG.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
## master
22

3+
### Fixes
4+
5+
* `[jest-cli]` Use `import-local` to support global Jest installations.
6+
37
## jest 22.0.7
48

59
### Fixes
610

7-
* `[jest-runner]` Fix memory leak in coverage reporting ([#5289](https://github.com/facebook/jest/pull/5289))
11+
* `[jest-runner]` Fix memory leak in coverage reporting
12+
([#5289](https://github.com/facebook/jest/pull/5289))
813

914
### Features
1015

11-
* `[jest-cli]` Make Jest exit without an error when no tests are found in
12-
the case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
16+
* `[jest-cli]` Make Jest exit without an error when no tests are found in the
17+
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
1318
having been passed to the CLI
1419

1520
## jest 22.0.6
1621

1722
### Fixes
1823

19-
* `[jest-jasmine2]` Fix memory leak in snapshot reporting ([#5279](https://github.com/facebook/jest/pull/5279))
20-
* `[jest-config]` Fix breaking change in `--testPathPattern` ([#5269](https://github.com/facebook/jest/pull/5269))
24+
* `[jest-jasmine2]` Fix memory leak in snapshot reporting
25+
([#5279](https://github.com/facebook/jest/pull/5279))
26+
* `[jest-config]` Fix breaking change in `--testPathPattern`
27+
([#5269](https://github.com/facebook/jest/pull/5269))
2128

2229
### Fixes
2330

2431
* `[docs]` Document caveat with mocks, Enzyme, snapshots and React 16
25-
([#5258](https://github.com/facebook/jest/issues/5258))
32+
([#5258](https://github.com/facebook/jest/issues/5258))
2633

2734
## jest 22.0.5
2835

packages/jest-cli/bin/jest.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
if (process.env.NODE_ENV == null) {
10-
process.env.NODE_ENV = 'test';
11-
}
9+
const importLocal = require('import-local');
10+
11+
if (!importLocal(__filename)) {
12+
if (process.env.NODE_ENV == null) {
13+
process.env.NODE_ENV = 'test';
14+
}
1215

13-
require('../build/cli').run();
16+
require('../build/cli').run();
17+
}

packages/jest-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"chalk": "^2.0.1",
99
"glob": "^7.1.2",
1010
"graceful-fs": "^4.1.11",
11+
"import-local": "^1.0.0",
1112
"is-ci": "^1.0.10",
1213
"istanbul-api": "^1.1.14",
1314
"istanbul-lib-coverage": "^1.1.1",

packages/jest-cli/src/cli/get_jest.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/jest-cli/src/cli/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as args from './args';
2323
import chalk from 'chalk';
2424
import createContext from '../lib/create_context';
2525
import getChangedFilesPromise from '../get_changed_files_promise';
26-
import getJest from './get_jest';
2726
import handleDeprecationWarnings from '../lib/handle_deprecation_warnings';
2827
import logDebugMessages from '../lib/log_debug_messages';
2928
import {print as preRunMessagePrint} from '../pre_run_message';
@@ -39,11 +38,8 @@ export async function run(maybeArgv?: Argv, project?: Path) {
3938
try {
4039
const argv: Argv = buildArgv(maybeArgv, project);
4140
const projects = getProjectListFromCLIArgs(argv, project);
42-
// If we're running a single Jest project, we might want to use another
43-
// version of Jest (the one that is specified in this project's package.json)
44-
const runCLIFn = getRunCLIFn(projects);
4541

46-
const {results, globalConfig} = await runCLIFn(argv, projects);
42+
const {results, globalConfig} = await runCLI(argv, projects);
4743
readResultsAndExit(results, globalConfig);
4844
} catch (error) {
4945
clearLine(process.stderr);
@@ -158,9 +154,6 @@ const getProjectListFromCLIArgs = (argv, project: ?Path) => {
158154
return projects;
159155
};
160156

161-
const getRunCLIFn = (projects: Array<Path>) =>
162-
projects.length === 1 ? getJest(projects[0]).runCLI : runCLI;
163-
164157
const printDebugInfoAndExitIfNeeded = (
165158
argv,
166159
globalConfig,

yarn.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,13 @@ immutable@^4.0.0-rc.7:
40214021
version "4.0.0-rc.9"
40224022
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.0.0-rc.9.tgz#1e6e0094e649013ec3742d2b5aeeca5eeda4f0bf"
40234023

4024+
import-local@^1.0.0:
4025+
version "1.0.0"
4026+
resolved "https://registry.yarnpkg.com/import-local/-/import-local-1.0.0.tgz#5e4ffdc03f4fe6c009c6729beb29631c2f8227bc"
4027+
dependencies:
4028+
pkg-dir "^2.0.0"
4029+
resolve-cwd "^2.0.0"
4030+
40244031
import-modules@^1.1.0:
40254032
version "1.1.0"
40264033
resolved "https://registry.yarnpkg.com/import-modules/-/import-modules-1.1.0.tgz#748db79c5cc42bb9701efab424f894e72600e9dc"
@@ -6131,6 +6138,12 @@ pkg-dir@^1.0.0:
61316138
dependencies:
61326139
find-up "^1.0.0"
61336140

6141+
pkg-dir@^2.0.0:
6142+
version "2.0.0"
6143+
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
6144+
dependencies:
6145+
find-up "^2.1.0"
6146+
61346147
61356148
version "2.0.1"
61366149
resolved "https://registry.yarnpkg.com/plist/-/plist-2.0.1.tgz#0a32ca9481b1c364e92e18dc55c876de9d01da8b"
@@ -6872,10 +6885,20 @@ [email protected]:
68726885
version "1.0.0"
68736886
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
68746887

6888+
resolve-cwd@^2.0.0:
6889+
version "2.0.0"
6890+
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
6891+
dependencies:
6892+
resolve-from "^3.0.0"
6893+
68756894
resolve-from@^1.0.0:
68766895
version "1.0.1"
68776896
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
68786897

6898+
resolve-from@^3.0.0:
6899+
version "3.0.0"
6900+
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
6901+
68796902
68806903
version "1.1.7"
68816904
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

0 commit comments

Comments
 (0)