-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Switch CLI to yargs #1109
Switch CLI to yargs #1109
Conversation
cbe9916
to
3fcd99c
Compare
@rotemmiz This PR is done now. It enables users to use the detox cli via environment variables, over the package.json and via configuration file. The CI seems to be flaky, so 🤷♂️ |
@@ -0,0 +1,26 @@ | |||
describe('build-framework-cache', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these kind of tests have not a lot of meaning, it just reimplements the production code, and checks that they are the same. I have a feeling we can give build-framework-cache.test.js
completely up.
detox/local-cli/build.test.js
Outdated
@@ -0,0 +1,115 @@ | |||
describe('build', () => { | |||
it('shows help text', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably drop shows help text
test, what does it check?
detox/local-cli/build.test.js
Outdated
mockPackageJson({ | ||
configurations: { | ||
only: { | ||
build: 'echo "I was build"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the sake of readability, can you change the strings to corespond to the config names?
detox/local-cli/build.test.js
Outdated
} | ||
} | ||
}); | ||
const mockExec = jest.fn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
const mockExec= jest.fn();
jest.mock('child_process', () => ({
execSync: mockExec
}));
be moved to the top of the suite? you add it in beforeEach
it('shows help text', async () => { | ||
jest.spyOn(process, 'exit'); // otherwise tests are aborted | ||
|
||
expect(await callCli('./clean-framework-cache', '--help')).toMatchInlineSnapshot(` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, meaningless test
detox/local-cli/test.js
Outdated
'artifacts-location': { | ||
alias: ['a', 'artifactsLocation'], | ||
group: 'Debugging', | ||
describe: '[EXPERIMENTAL] Artifacts (logs, screenshots, etc) root directory.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is not experimental anymore, if you can drop the [EXPERIMENTAL]
text across the artifacts args, it would be super
detox/local-cli/test.js
Outdated
|
||
clearDeviceRegistryLockFile(); | ||
|
||
if (!program.configuration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many validation/assigning steps here, does yargs have a custom processing functionality for args? if it does, it should probably go in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does through middlewares, but I would suggest to move it into a separate PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!!
detox/local-cli/test.js
Outdated
} | ||
|
||
function runMocha() { | ||
const loglevel = program.loglevel ? `--loglevel ${program.loglevel}` : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do something automatic with this section? I hate adding a new param every time its being added to cli api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ Not that I'm aware of, maybe we should have a map between our flags and mocha or jest flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still hate the fact that mocha has no mechanism like jest for having environment. This would be way more natural from a jest perspective than the wrapping that we currently do
@@ -34,6 +34,53 @@ detox [options] [command] | |||
| --- | --- | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
Also to be done: #1083 (comment) |
b7b726c
to
b189264
Compare
b189264
to
5ff5dfd
Compare
@rotemmiz This is ready for review now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Mr Schmidt!
There are a few minor issues regarding cleanup and location of new files, please see my notes.
detox/cli.js
Outdated
@@ -0,0 +1,23 @@ | |||
#!/usr/bin/env node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you prefer putting this here and not inside /local-cli
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not put .
as commandDir
and I did not want to have this extra level of nesting 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
- "detox": "local-cli/detox.js"
+ "detox": "cli.js"
This is a part of the changes you made in this PR, why can't it be reverted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this part in my changes. At least as far as I understand it. Feel free to try it, though.
detox/local-cli/init.js
Outdated
console.log("init handler", argv) | ||
switch (argv.runner) { | ||
case "mocha": | ||
createMochaFolderE2E(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please indent the code
detox/local-cli/test.js
Outdated
|
||
clearDeviceRegistryLockFile(); | ||
|
||
if (!program.configuration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!!
@rotemmiz Answered and fixed everything 💪 |
@DanielMSchmidt I moved cli.js to local-cli.js.
I couldn't find where
But I can't see how that is applied into |
@rotemmiz I think the problem is that we don't successfully filter out the options passed via CLI, they just get passed through as it seems |
The issue seems bigger than the purposed fix in a0582e3. |
@rotemmiz Ah yeah, that explains why I did not catch it in the very first moment, when this feature is not enabled, interesting 🤔 I'll think a bit about how to fix this, I mean we basically would also need to be carful about all other input options, so just filtering them out might not be the best option |
Both |
@rotemmiz I think I got it, at least theoretically. We could create a new instance of a yargs program without any configuration within collectExtraArgs, then it should work just fine. |
Switch commander interface out with
yargs
, which is a more reliable interface and the following awesome features:Resolves #1132.
Addresses #1238.