Skip to content

Commit

Permalink
fix(jest-cli): use import-local to support global Jest installations (
Browse files Browse the repository at this point in the history
#5304)

* fix(jest-cli): use `import-local` to support global Jest installations

Fixes #5294

* docs: update changelog
  • Loading branch information
SimenB authored and cpojer committed Jan 14, 2018
1 parent c9cf010 commit 6e788b1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 65 deletions.
20 changes: 14 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
## master

### Fixes

* `[jest-cli]` Use `import-local` to support global Jest installations.
([#5304](https://github.com/facebook/jest/pull/5304))

## jest 22.0.7

### Fixes

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

### Features

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

### Fixes
Expand All @@ -24,13 +30,15 @@

### Fixes

* `[jest-jasmine2]` Fix memory leak in snapshot reporting ([#5279](https://github.com/facebook/jest/pull/5279))
* `[jest-config]` Fix breaking change in `--testPathPattern` ([#5269](https://github.com/facebook/jest/pull/5269))
* `[jest-jasmine2]` Fix memory leak in snapshot reporting
([#5279](https://github.com/facebook/jest/pull/5279))
* `[jest-config]` Fix breaking change in `--testPathPattern`
([#5269](https://github.com/facebook/jest/pull/5269))

### Fixes

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

## jest 22.0.5

Expand Down
12 changes: 8 additions & 4 deletions packages/jest-cli/bin/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
* LICENSE file in the root directory of this source tree.
*/

if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'test';
}
const importLocal = require('import-local');

if (!importLocal(__filename)) {
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'test';
}

require('../build/cli').run();
require('../build/cli').run();
}
1 change: 1 addition & 0 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"chalk": "^2.0.1",
"glob": "^7.1.2",
"graceful-fs": "^4.1.11",
"import-local": "^1.0.0",
"is-ci": "^1.0.10",
"istanbul-api": "^1.1.14",
"istanbul-lib-coverage": "^1.1.1",
Expand Down
47 changes: 0 additions & 47 deletions packages/jest-cli/src/cli/get_jest.js

This file was deleted.

9 changes: 1 addition & 8 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as args from './args';
import chalk from 'chalk';
import createContext from '../lib/create_context';
import getChangedFilesPromise from '../get_changed_files_promise';
import getJest from './get_jest';
import handleDeprecationWarnings from '../lib/handle_deprecation_warnings';
import logDebugMessages from '../lib/log_debug_messages';
import {print as preRunMessagePrint} from '../pre_run_message';
Expand All @@ -39,11 +38,8 @@ export async function run(maybeArgv?: Argv, project?: Path) {
try {
const argv: Argv = buildArgv(maybeArgv, project);
const projects = getProjectListFromCLIArgs(argv, project);
// If we're running a single Jest project, we might want to use another
// version of Jest (the one that is specified in this project's package.json)
const runCLIFn = getRunCLIFn(projects);

const {results, globalConfig} = await runCLIFn(argv, projects);
const {results, globalConfig} = await runCLI(argv, projects);
readResultsAndExit(results, globalConfig);
} catch (error) {
clearLine(process.stderr);
Expand Down Expand Up @@ -158,9 +154,6 @@ const getProjectListFromCLIArgs = (argv, project: ?Path) => {
return projects;
};

const getRunCLIFn = (projects: Array<Path>) =>
projects.length === 1 ? getJest(projects[0]).runCLI : runCLI;

const printDebugInfoAndExitIfNeeded = (
argv,
globalConfig,
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,13 @@ immutable@^4.0.0-rc.7:
version "4.0.0-rc.9"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.0.0-rc.9.tgz#1e6e0094e649013ec3742d2b5aeeca5eeda4f0bf"

import-local@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/import-local/-/import-local-1.0.0.tgz#5e4ffdc03f4fe6c009c6729beb29631c2f8227bc"
dependencies:
pkg-dir "^2.0.0"
resolve-cwd "^2.0.0"

import-modules@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/import-modules/-/import-modules-1.1.0.tgz#748db79c5cc42bb9701efab424f894e72600e9dc"
Expand Down Expand Up @@ -6131,6 +6138,12 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"

pkg-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
dependencies:
find-up "^2.1.0"

plist@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/plist/-/plist-2.0.1.tgz#0a32ca9481b1c364e92e18dc55c876de9d01da8b"
Expand Down Expand Up @@ -6872,10 +6885,20 @@ requires-port@1.x.x:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"

resolve-cwd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
dependencies:
resolve-from "^3.0.0"

resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve-from@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"

resolve@1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
Expand Down

0 comments on commit 6e788b1

Please sign in to comment.