-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error handling for unexpected numeric arguments passed to cli (#…
…5263) * Fix 5028 // Numerical arguments to cli throw uncaught error This PR throws a custom error which is (hopefully) easier to understand when: i. a numerical argument is passed to mocha cli ii. numerical value is used as a value for one of the mocha flags that is not compatible with numerical values. Signed-off-by: Dinika Saxena <dinika@greyllama.cc> * Use type-check to throw error instead of a broad try/catch Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> * Rename numerical to numeric Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> * Find flag for mocha cli after parsing yargs * Find flag for faulty numeric args before yargs parser Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> * Add js-doc private keyword to fix netlify doc deployment * [Style] // Reduce code duplication * Add an "it" block for each flag for easier debug-ability Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> * Remove ? from flag since it cannot be undefined * Add test cases for empty string checks for isNumeric * Do not add extra leading -- in error message for flag * Throw error for numeric positional arg after yargs-parser has parsed args Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> * Revert timeout and slow as string flags so that they can accept human readable values Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com> --------- Signed-off-by: Dinika Saxena <dinika@greyllama.cc> Signed-off-by: Dinika Saxena <dinikasaxenas@gmail.com>
- Loading branch information
Showing
6 changed files
with
249 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const { | ||
types, | ||
expectedTypeForFlag | ||
} = require('../../../lib/cli/run-option-metadata'); | ||
|
||
describe('mocha-flags', function () { | ||
describe('expectedTypeForFlag()', function () { | ||
Object.entries(types).forEach(([dataType, flags]) => { | ||
flags.forEach(flag => { | ||
it(`returns expected ${flag}'s type as ${dataType}`, function () { | ||
expect(expectedTypeForFlag(flag), 'to equal', dataType); | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns undefined for node flags', function () { | ||
expect(expectedTypeForFlag('--throw-deprecation'), 'to equal', undefined); | ||
expect(expectedTypeForFlag('throw-deprecation'), 'to equal', undefined); | ||
}); | ||
|
||
it('returns undefined for unsupported flags', function () { | ||
expect(expectedTypeForFlag('--foo'), 'to equal', undefined); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters