Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use yargs's built-in version instead of rolling our own #6215

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -65,8 +65,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 @@ -163,7 +161,7 @@ const buildArgv = (maybeArgv: ?Argv, project: ?Path) => {
.options(args.options)
.epilogue(args.docs)
.check(args.check)
.version(false).argv;
.version(`v${VERSION}`).argv;
Copy link
Member Author

@SimenB SimenB May 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without passing in the version, it printed undefined. Not sure why... Probably something weird with using the ./jest script and cwd, or something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this?

If no arguments are passed to version (.version()), yargs will parse the package.json of your module and use its version value.

https://github.com/yargs/yargs/blob/master/docs/api.md#versionoption-description-version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but that prints undefined. It seems like it looks up from cwd and uses the package.json there, instead of the closest local one.

This is only an issue when using ./jest in this repo, it works doing node package/jest-cli/bin/jest.js --version


validateCLIOptions(
argv,
Expand Down Expand Up @@ -210,11 +208,6 @@ const printDebugInfoAndExitIfNeeded = (
}
};

const printVersionAndExit = outputStream => {
outputStream.write(`v${VERSION}\n`);
exit(0);
};

const ensureNoDuplicateConfigs = (parsedConfigs, projects, rootConfigPath) => {
const configPathMap = new Map();

Expand Down