Skip to content

Commit

Permalink
chore: use yargs's built-in version instead of rolling our own (#6215)
Browse files Browse the repository at this point in the history
* chore: use yargs's built-in `version` instead of rolling our own

* link to PR

* don't provide custom version
  • Loading branch information
SimenB authored and cpojer committed May 22, 2018
1 parent f55f3d8 commit beda6b5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/__tests__/version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
17 changes: 9 additions & 8 deletions jest
Original file line number Diff line number Diff line change
@@ -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 "$@"
11 changes: 1 addition & 10 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit beda6b5

Please sign in to comment.