Skip to content

Commit beda6b5

Browse files
SimenBcpojer
authored andcommitted
chore: use yargs's built-in version instead of rolling our own (#6215)
* chore: use yargs's built-in `version` instead of rolling our own * link to PR * don't provide custom version
1 parent f55f3d8 commit beda6b5

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163

164164
### Chore & Maintenance
165165

166+
* `[jest-cli]` Use yargs's built-in `version` instead of rolling our own
167+
([#6215](https://github.com/facebook/jest/pull/6215))
166168
* `[docs]` Add explanation on how to mock methods not implemented in JSDOM
167169
* `[jest-jasmine2]` Simplify `Env.execute` and TreeProcessor to setup and clean
168170
resources for the top suite the same way as for all of the children suites

integration-tests/__tests__/version.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test('works with jest.config.js', () => {
2929
});
3030

3131
const {status, stdout, stderr} = runJest(DIR, ['--version']);
32-
expect(stdout).toMatch(/v\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*$/);
32+
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*$/);
3333
// Only version gets printed and nothing else
3434
expect(stdout.split(/\n/)).toHaveLength(1);
3535
expect(stderr).toBe('');

jest

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#!/usr/bin/env node
2-
/**
3-
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
4-
*
5-
* This source code is licensed under the MIT license found in the
6-
* LICENSE file in the root directory of this source tree.
7-
*/
1+
#!/usr/bin/env sh
82

9-
require('./packages/jest-cli/bin/jest');
3+
: '
4+
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
5+
6+
This source code is licensed under the MIT license found in the
7+
LICENSE file in the root directory of this source tree.
8+
'
9+
10+
node ./packages/jest-cli/bin/jest "$@"

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
1414
import {Console, clearLine, createDirectory} from 'jest-util';
1515
import {validateCLIOptions} from 'jest-validate';
1616
import {readConfig, deprecationEntries} from 'jest-config';
17-
import {version as VERSION} from '../../package.json';
1817
import * as args from './args';
1918
import chalk from 'chalk';
2019
import createContext from '../lib/create_context';
@@ -65,8 +64,6 @@ export const runCLI = async (
6564
const outputStream =
6665
argv.json || argv.useStderr ? process.stderr : process.stdout;
6766

68-
argv.version && printVersionAndExit(outputStream);
69-
7067
const {globalConfig, configs, hasDeprecationWarnings} = getConfigs(
7168
projects,
7269
argv,
@@ -162,8 +159,7 @@ const buildArgv = (maybeArgv: ?Argv, project: ?Path) => {
162159
.alias('help', 'h')
163160
.options(args.options)
164161
.epilogue(args.docs)
165-
.check(args.check)
166-
.version(false).argv;
162+
.check(args.check).argv;
167163

168164
validateCLIOptions(
169165
argv,
@@ -210,11 +206,6 @@ const printDebugInfoAndExitIfNeeded = (
210206
}
211207
};
212208

213-
const printVersionAndExit = outputStream => {
214-
outputStream.write(`v${VERSION}\n`);
215-
exit(0);
216-
};
217-
218209
const ensureNoDuplicateConfigs = (parsedConfigs, projects, rootConfigPath) => {
219210
const configPathMap = new Map();
220211

0 commit comments

Comments
 (0)