diff --git a/CHANGELOG.md b/CHANGELOG.md index 26c1584f6485..802092cf6be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -161,6 +161,8 @@ ### Chore & Maintenance +* `[jest-cli]` Use yargs's built-in `version` instead of rolling our own + ([#6215](https://github.com/facebook/jest/pull/6215)) * `[docs]` Add explanation on how to mock methods not implemented in JSDOM * `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean resources for the top suite the same way as for all of the children suites diff --git a/integration-tests/__tests__/version.test.js b/integration-tests/__tests__/version.test.js index 9c7dc8a99b1f..b79be3d04aa5 100644 --- a/integration-tests/__tests__/version.test.js +++ b/integration-tests/__tests__/version.test.js @@ -29,7 +29,7 @@ test('works with jest.config.js', () => { }); const {status, stdout, stderr} = runJest(DIR, ['--version']); - expect(stdout).toMatch(/v\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*$/); + expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*$/); // Only version gets printed and nothing else expect(stdout.split(/\n/)).toHaveLength(1); expect(stderr).toBe(''); diff --git a/jest b/jest index c48ac6707c93..3795fec3995b 100755 --- a/jest +++ b/jest @@ -1,9 +1,10 @@ -#!/usr/bin/env node -/** - * Copyright (c) 2014-present, Facebook, Inc. 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. - */ +#!/usr/bin/env sh -require('./packages/jest-cli/bin/jest'); +: ' +Copyright (c) 2014-present, Facebook, Inc. 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. +' + +node ./packages/jest-cli/bin/jest "$@" diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index 4835ebcf49ce..37c59b3ea2a6 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -14,7 +14,6 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; import {Console, clearLine, createDirectory} from 'jest-util'; import {validateCLIOptions} from 'jest-validate'; import {readConfig, deprecationEntries} from 'jest-config'; -import {version as VERSION} from '../../package.json'; import * as args from './args'; import chalk from 'chalk'; import createContext from '../lib/create_context'; @@ -65,8 +64,6 @@ export const runCLI = async ( const outputStream = argv.json || argv.useStderr ? process.stderr : process.stdout; - argv.version && printVersionAndExit(outputStream); - const {globalConfig, configs, hasDeprecationWarnings} = getConfigs( projects, argv, @@ -162,8 +159,7 @@ const buildArgv = (maybeArgv: ?Argv, project: ?Path) => { .alias('help', 'h') .options(args.options) .epilogue(args.docs) - .check(args.check) - .version(false).argv; + .check(args.check).argv; validateCLIOptions( argv, @@ -210,11 +206,6 @@ const printDebugInfoAndExitIfNeeded = ( } }; -const printVersionAndExit = outputStream => { - outputStream.write(`v${VERSION}\n`); - exit(0); -}; - const ensureNoDuplicateConfigs = (parsedConfigs, projects, rootConfigPath) => { const configPathMap = new Map();