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

Refactor CLI #3862

Merged
merged 1 commit into from
Jun 20, 2017
Merged

Refactor CLI #3862

merged 1 commit into from
Jun 20, 2017

Conversation

aaronabramov
Copy link
Contributor

I'm working on updating internal fb runner to work with the latest version of Jest, and unfortunately it's very tightly coupled to CLI implementation of Jest open source project.

This PR doesn't add/change any functionality, but rather renames/moves things around.

my main confusion was around the runner modules (bin/jest, run(), runCLI(), execute(), runJest(), TestRunner, runTests()) which have similar names and seem to do the same thing.

and configuration objects that are shared between the runner functions (Yarn args object, argv, DefaultOptions, InitialObjects, ProjectConfig, GlobalConfig, testNamePattern, testPathPattern, maxWorkers, pattern, etc.). Most of them seem to be intended to be immutable, but unfortunately get mutated throughout the flow (updateArgv, globalConfig = Object.freeze(Object.assign({}, globalConfig, {newValue: true}))).

we talked with @thymikee and @cpojer and came up with a plan to merge most of the configuration options into globalConfig and stop passing argv right after we parse the initial config value.

This PR renames some of the object/variable/function names, and splits up/modularizes the running pipeline for jest (rather than having everything in one big function)

@@ -33,7 +33,7 @@ type Options = {|
withAncestor?: boolean,
|};

export type PathPattern = {|
export type PathPatternObject = {|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have testNamePattern and testPathPattern, which is confusing. Also this object seem to have more info than just a pattern

Copy link
Member

Choose a reason for hiding this comment

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

I don't like adding "Object" because everything in JS is an object, hence why it was called PathPattern. How about TestSelectionConfig or TestSelectionPattern because that is what it actually is?

Note: Previous names of this were PathPatternInfo and PathInfo or things like it. It's a tough one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i like it (TestSelectionConfig), let's make it that

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the TestSelectionConfig too. I'll stamp as soon as you rename it

import watch from '../watch';
import yargs from 'yargs';

function run(maybeArgv?: Argv, project?: Path) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

run and runCLI are two main functions that get exported and both of them are just a few lines now (all data massaging/parsing is modularized and extracted into separate functions).

ideally i would name run as findJestAndRun, but those are part of public interface

@@ -16,7 +16,7 @@ import {version as VERSION} from '../../package.json';
const logDebugMessages = (
globalConfig: GlobalConfig,
config: ProjectConfig,
pipe: stream$Writable | tty$WriteStream,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i wasn't sure what exactly pipe object was until i saw the usage of it. I thought outputStream would be a more descriptive name

@codecov-io
Copy link

codecov-io commented Jun 20, 2017

Codecov Report

Merging #3862 into master will decrease coverage by 0.05%.
The diff coverage is 11.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3862      +/-   ##
==========================================
- Coverage   57.63%   57.58%   -0.06%     
==========================================
  Files         194      195       +1     
  Lines        6782     6792      +10     
  Branches        6        6              
==========================================
+ Hits         3909     3911       +2     
- Misses       2870     2878       +8     
  Partials        3        3
Impacted Files Coverage Δ
packages/jest-cli/src/reporters/SummaryReporter.js 22.58% <0%> (ø) ⬆️
packages/jest-cli/src/runJest.js 0% <0%> (ø) ⬆️
packages/jest-cli/src/TestRunner.js 28.46% <0%> (+3.15%) ⬆️
packages/jest-cli/src/SearchSource.js 71.01% <0%> (ø) ⬆️
packages/jest-cli/src/lib/getTestPathPattern.js 52.94% <100%> (ø) ⬆️
packages/jest-cli/src/lib/logDebugMessages.js 100% <100%> (ø) ⬆️
packages/jest-cli/src/testResultHelpers.js 12.5% <12.5%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09efdba...93d32ef. Read the comment docs.

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Looks good. Left couple of comments for you to take care of.

_patchGlobalFSModule();

// If we output a JSON object, we can't write anything to stdout, since
// it'll break the JSON stracture and it won't be valide.
Copy link
Collaborator

Choose a reason for hiding this comment

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

stracture -> structure
valide -> valid


exports.run = run;
exports.runCLI = runCLI;
const parsedConfig = readConfig(argv, projects[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is readConfig(argv, projects[0]) called twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cause i can't even read my own code haha 😪

Copy link
Collaborator

Choose a reason for hiding this comment

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

sheldon_cooper_there_there

addResult,
buildFailureTestResult,
makeEmptyTestResult,
} from './test_result_utils';
Copy link
Collaborator

Choose a reason for hiding this comment

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

@cpojer won't be happy haha. Maybe we can name it test_result_helpers. I like that we're reusing makeEmptyTestResult – how about renaming it to makeEmptyAggregatedResult, just like we call its type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it can't be makeEmptyAggregatedResult cause it has other utility functions in it (make test result, add test to aggregated result).
I'll rename it to helpers, but to me it's just another word for utilities :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was referring just to rename makeEmptyTestResult -> makeEmptyAggregatedResult if that makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh! yeah, that makes total sense!

let projects = [];
if (argv.projects) {
projects = argv.projects;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about

const projects = argv.projects ? argv.projects : [];

We're doing condition check and assignments anyway.

@aaronabramov aaronabramov force-pushed the refactor-CLI branch 3 times, most recently from 52580c4 to 5259bf9 Compare June 20, 2017 19:05
@@ -72,9 +72,6 @@ exports[`jest --showConfig outputs config info and exits 1`] = `
"mapCoverage": false,
"noStackTrace": false,
"notify": false,
"projects": [
"/mocked/root/path/jest/integration_tests/verbose_reporter"
],
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was an intermediate process.cwd() value that was attached to a config in the process of parsing other configs. I change the code to pass it directly

@cpojer
Copy link
Member

cpojer commented Jun 20, 2017

I'm on board with this, feel free to merge as soon as @thymikee gives the ok. I won't have time to review this in full, but any simplification here makes a lot of sense. Make sure not to break the world, please.

@thymikee
Copy link
Collaborator

Node 4 is green locally 👍.

@aaronabramov aaronabramov merged commit f0d2dea into jestjs:master Jun 20, 2017
@aaronabramov aaronabramov deleted the refactor-CLI branch June 20, 2017 21:15
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants