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

fix: Add supported choices to --target option #1644

Merged
merged 4 commits into from
Jul 11, 2019
Merged

fix: Add supported choices to --target option #1644

merged 4 commits into from
Jul 11, 2019

Conversation

onlywicked
Copy link
Contributor

Fixes #1642

@coveralls
Copy link

coveralls commented Jun 30, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 08feb7e on onlywicked:fix-1642-target into 644188a on mozilla:master.

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! I manually verified that the functionality works as desired.
In order to have automated test coverage, some changes are needed.

sinon.assert.notCalled(androidRunnerStub);
sinon.assert.notCalled(desktopRunnerStub);
});

Copy link
Member

Choose a reason for hiding this comment

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

This test doesn't help much, because this tests the internal implementation, and not the CLI frontend. If you add sinon.assert.notCalled(cmd.options.MultiExtensionRunner), then you would see that the test fails, because the runner is run anyway.

There are two relevant conditions to check:

  1. -t firefox-desktop works.
  2. -t firefox-desktop -t not-supported -t firefox-desktop results in an error message.

To test (1), you can add the parameter after this line:

'--firefox', fakeFirefoxPath,

To test (2), you could copy that test, cut the parts that we don't need, and add it to the same file.

https://github.com/mozilla/web-ext/blob/master/tests/functional/test.cli.run.js#L11

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be fine if I use assert to validate the exitCode and stderr?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that works. The reportCommandErrors in the existing test mainly exists to help with debugging if there is an unexpected test failure.

@@ -442,6 +442,7 @@ Example: $0 --help run.
default: 'firefox-desktop',
demandOption: false,
type: 'array',
choices: ['firefox-desktop', 'firefox-android'],
Copy link
Member

Choose a reason for hiding this comment

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

Adding choices here automatically causes them to be added to the help test, when web-ext run --help is used. Now the description (a few lines back) can also be simplified. Could you remove the text between parentheses to shorten the description?

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

This looks good. I have two minor comments.

src/program.js Outdated
@@ -436,8 +436,8 @@ Example: $0 --help run.
.command('run', 'Run the extension', commands.run, {
'target': {
alias: 't',
describe: 'The extensions runners to enable (e.g. firefox-desktop, ' +
'firefox-android). Specify this option multiple times to ' +
describe: 'The extensions runners to enable. ' +
Copy link
Member

Choose a reason for hiding this comment

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

Could you combine this line with the next two lines so that the string is only cut when the 80-character line limit has been reached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@@ -47,4 +48,31 @@ describe('web-ext run', () => {
}
});
}));

it('should not accept: --target INVALIDTARGET',
() => withTempAddonDir(
Copy link
Member

Choose a reason for hiding this comment

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

In this test, the program is supposed to exit early due to invalid command line parameters. Therefore it is not necessary to create a temporary add-on. You can simplify the test:

it('should not accept: --target INVALIDTARGET', async () => {
  const argv = [ ... ] // 'run' and the --target options only
  return execWebExt(argv, {}).then(({exitCode, stderr}) => {
    ...
  });
});

Combine lines in "describe" to follow 80 character line limit
The program exit eary due to invalid command line parameters. Therefore
it is unnecessary to create a temporary add-on or pass spawnOptions.
@Rob--W Rob--W changed the title Fixes #1642: Added choices for target option fix: Add supported choices to --target option Jul 11, 2019
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Thanks for your patch!

@Rob--W Rob--W merged commit 739aa52 into mozilla:master Jul 11, 2019
@caitmuenster
Copy link

Hey @onlywicked, thanks so much for the patch! 🎉 Your contribution has been added to our recognition wiki.

Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for you!

@onlywicked
Copy link
Contributor Author

onlywicked commented Jul 14, 2019

Hey @onlywicked, thanks so much for the patch! 🎉 Your contribution has been added to our recognition wiki.

Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for you!

I have signed up for mozillians.org.
So, can you please vouch for me?

@caitmuenster
Copy link

Sorry for the delay, @onlywicked! Your Mozillians profile is now vouched. ✨

Welcome onboard! We look forward to seeing you around the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--target / -t flag with an invalid value does not result in any meaningful error message
4 participants