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 timeout/slow string values and duplicate arguments #3831

Merged
merged 2 commits into from May 17, 2019

Conversation

boneskull
Copy link
Member

@boneskull boneskull commented Mar 12, 2019

This fixes two problems:

  1. Duplicate values are no longer allowed on the command line, and an error will be thrown (e.g., --timeout 0 --timeout 0)
  2. String values of timeout and slow (e.g., 1s, 500ms) are no longer evaluated to NaN (because their type was set to number). It appears that a value of NaN would cause timeouts to be disabled.

Ref: #3817

UPDATE: Duplicate arguments are now allowed; the last value is chosen.

@boneskull boneskull added type: bug a defect, confirmed by a maintainer semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Mar 12, 2019
@coveralls
Copy link

coveralls commented Mar 12, 2019

Coverage Status

Coverage increased (+0.003%) to 91.822% when pulling 6c8b7e1 on boneskull/timeout-fixes into 94033bf on master.

@plroebuck
Copy link
Contributor

plroebuck commented Mar 12, 2019

Duplicate values are no longer allowed on the command line, and an error will be thrown (e.g., --timeout 0 --timeout 0)

This is a completely valid cmdline argument usage -- last value wins. It's not an error.

@juergba
Copy link
Member

juergba commented Mar 13, 2019

This is a completely valid cmdline argument usage -- last value wins. It's not an error.

Agree. Sometimes it's even necessary to overwrite flags, i.e. ones set by IDE's.

lib/cli/run.js Outdated Show resolved Hide resolved
lib/cli/run.js Outdated Show resolved Hide resolved
@boneskull
Copy link
Member Author

This is a completely valid cmdline argument usage -- last value wins. It's not an error.

Hm, ok. Assuming the array yargs-parser gives us is in order, then I can just pop it.

@boneskull
Copy link
Member Author

@juergba @plroebuck I've changed this to use the last value instead of throwing an exception.

lib/cli/run.js Outdated Show resolved Hide resolved
@boneskull boneskull self-assigned this Mar 14, 2019
Copy link
Member

@juergba juergba left a comment

Choose a reason for hiding this comment

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

LGTM, except the duplicate test already mentioned.

(there can still be duplicate arguments within one single config file)

},
{stdio: 'pipe'}
);
describe('when argument is missing required value', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Said this before and provided code for it.
This should be run for all arguments expecting a value, not just --ui.

@juergba
Copy link
Member

juergba commented Mar 21, 2019

I haven't understood this "yargs" / "yargs-parser" thing completely, yet.

  • why can't "yargs-parser" use the default values defined in lib/cli/run.js
  • couldn't we use the duplicate-arguments-array option to reduce duplicate arguments?
var parse = require('yargs-parser');

var args = parse(
    ['--timeout', '2s', '--timeout', '1s', '--timeout', '800'], {
        string: ['timeout'],
        configuration: {
            'duplicate-arguments-array': false,
            'camel-case-expansion': false
        }
});
console.log(args);         // { _: [], timeout: '800' }

juergba
juergba previously requested changes May 2, 2019
lib/cli/run.js Outdated
.forEach(opt => {
argv[opt] = argv[opt].pop();
});

Copy link
Member

Choose a reason for hiding this comment

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

This part does not work correctly:

  • input per CLI: --slow 5 --slow 10
  • result after parsing: s: ["5"], slow: "10"

@juergba juergba force-pushed the boneskull/timeout-fixes branch 2 times, most recently from bea695b to 2936367 Compare May 3, 2019 09:09
@juergba juergba added status: needs review a maintainer should (re-)review this pull request area: node.js command-line-or-Node.js-specific labels May 3, 2019
@juergba
Copy link
Member

juergba commented May 3, 2019

There is a bug in "yargs-parser" where the coerce function returns a value of type number as string. I opened an issue for that.

This affects the parsing of our --retries option and I had to adapt some of our tests. Nevertheless there are no implications since Yargs#parse (without coerce function) converts the value back to number.

Ready for review.

@juergba
Copy link
Member

juergba commented May 9, 2019

I have chosen yargs-parser#coerce() in order to reduce duplicate arguments:

  • it reduces the flags incl. all its aliases
  • it is part of loadOptions() which is a public function. This is not the case with yargs.coerce(). Arguments should be reduced when a third party package depends on Mocha's loadOptions().

@juergba juergba requested review from markowsiak and Bamieh May 9, 2019 07:15
@juergba juergba requested a review from plroebuck May 9, 2019 07:16
@juergba juergba dismissed their stale review May 10, 2019 06:42

outdated

@plroebuck
Copy link
Contributor

Upstream fix for yargs-parser unnecessary then?

@juergba
Copy link
Member

juergba commented May 12, 2019

For our purposes, yes unnecessary.

@juergba
Copy link
Member

juergba commented May 16, 2019

I will merge these changes tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific semver-patch implementation requires increase of "patch" version number; "bug fixes" type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants