Skip to content

Commit 9c755e0

Browse files
authoredFeb 1, 2021
fix(cli): temporarily disable strict parameters validation (#3641)
As discussed in #3625 there are multiple cases, where Karma users rely on the possibility to pass arbitrary options/arguments to the karma CLI. These arguments are either handled in a `karma.conf.js` file or are consumed by Karma plugins. Given the disruptive effect of the strict parameters validation and the lack of the feasible workarounds, the feature is reverted until we have better understanding of the custom options/arguments use cases and can implement a solution which works for everybody.
1 parent dbd1943 commit 9c755e0

File tree

2 files changed

+19
-44
lines changed

2 files changed

+19
-44
lines changed
 

‎lib/cli.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function describeRoot () {
153153
.command('stop [configFile]', 'Stop the server.', describeStop)
154154
.command('completion', 'Shell completion for karma.', describeCompletion)
155155
.demandCommand(1, 'Command not specified.')
156-
.strict()
156+
.strictCommands()
157157
.describe('help', 'Print usage and options.')
158158
.describe('version', 'Print current version.')
159159
}
@@ -164,6 +164,7 @@ function describeInit (yargs) {
164164
'INIT - Initialize a config file.\n\n' +
165165
'Usage:\n' +
166166
' $0 init [configFile]')
167+
.strictCommands(false)
167168
.version(false)
168169
.positional('configFile', {
169170
describe: 'Name of the generated Karma configuration file',
@@ -215,6 +216,7 @@ function describeRun (yargs) {
215216
'RUN - Run the tests (requires running server).\n\n' +
216217
'Usage:\n' +
217218
' $0 run [configFile] [-- <clientArgs>]')
219+
.strictCommands(false)
218220
.version(false)
219221
.positional('configFile', {
220222
describe: 'Path to the Karma configuration file',
@@ -247,6 +249,7 @@ function describeStop (yargs) {
247249
'STOP - Stop the server (requires running server).\n\n' +
248250
'Usage:\n' +
249251
' $0 stop [configFile]')
252+
.strictCommands(false)
250253
.version(false)
251254
.positional('configFile', {
252255
describe: 'Path to the Karma configuration file',

‎test/e2e/cli.feature

+15-43
Original file line numberDiff line numberDiff line change
@@ -55,52 +55,24 @@ Feature: CLI
5555
--help Print usage and options. [boolean]
5656
--version Print current version. [boolean]
5757
58-
Unknown argument: strat
58+
Unknown command: strat
5959
"""
6060

61-
Scenario: Error when option is unknown
62-
When I execute Karma with arguments: "start --invalid-option"
63-
Then the stderr is exactly:
61+
Scenario: No error when unknown option and argument are passed in
62+
Given a configuration with:
6463
"""
65-
Karma - Spectacular Test Runner for JavaScript.
66-
67-
START - Start the server / do a single run.
68-
69-
Usage:
70-
karma start [configFile]
71-
72-
Positionals:
73-
configFile Path to the Karma configuration file [string]
74-
75-
Options:
76-
--help Print usage and options. [boolean]
77-
--port <integer> Port where the server is running.
78-
--auto-watch Auto watch source files and run on change.
79-
--detached Detach the server.
80-
--no-auto-watch Do not watch source files.
81-
--log-level <disable | error | warn | info | debug> Level
82-
of logging.
83-
--colors Use colors when reporting and printing logs.
84-
--no-colors Do not use colors when reporting or printing
85-
logs.
86-
--reporters List of reporters (available: dots, progress,
87-
junit, growl, coverage).
88-
--browsers List of browsers to start (eg. --browsers
89-
Chrome,ChromeCanary,Firefox).
90-
--capture-timeout <integer> Kill browser if does not capture in
91-
given time [ms].
92-
--single-run Run the test when browsers captured and exit.
93-
--no-single-run Disable single-run.
94-
--report-slower-than <integer> Report tests that are slower than
95-
given time [ms].
96-
--fail-on-empty-test-suite Fail on empty test suite.
97-
--no-fail-on-empty-test-suite Do not fail on empty test suite.
98-
--fail-on-failing-test-suite Fail on failing test suite.
99-
--no-fail-on-failing-test-suite Do not fail on failing test suite.
100-
--format-error A path to a file that exports the format
101-
function. [string]
102-
103-
Unknown arguments: invalid-option, invalidOption
64+
files = ['basic/plus.js', 'basic/test.js'];
65+
browsers = ['ChromeHeadlessNoSandbox'];
66+
plugins = [
67+
'karma-jasmine',
68+
'karma-chrome-launcher'
69+
];
70+
"""
71+
When I execute Karma with arguments: "start sandbox/karma.conf.js unknown-argument --unknown-option"
72+
Then it passes with:
73+
"""
74+
..
75+
Chrome Headless
10476
"""
10577

10678
Scenario: Init command help

0 commit comments

Comments
 (0)
Please sign in to comment.