Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 5856037

Browse files
authored
fix(cli): Allow frameworks to specify flags they recognize. (#3994)
Fix for #3978. Our initial plan to allow setting --disableChecks with an environment variable is insufficient, since the custom framework isn't even require()'d until after the config is parsed. This moves the unknown flag check into the runner, and gives frameworks a way to specify extra flags they accept.
1 parent e68dcf1 commit 5856037

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

lib/cli.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,10 @@ if (argv.version) {
175175
process.exit(0);
176176
}
177177

178-
if (!argv.disableChecks) {
179-
// Check to see if additional flags were used.
180-
let unknownKeys: string[] = Object.keys(argv).filter((element: string) => {
181-
return element !== '$0' && element !== '_' && allowedNames.indexOf(element) === -1;
182-
});
183-
184-
if (unknownKeys.length > 0) {
185-
throw new Error(
186-
'Found extra flags: ' + unknownKeys.join(', ') +
187-
', please use --disableChecks flag to disable the Protractor CLI flag checks.');
188-
}
189-
}
178+
// Check to see if additional flags were used.
179+
argv.unknownFlags_ = Object.keys(argv).filter((element: string) => {
180+
return element !== '$0' && element !== '_' && allowedNames.indexOf(element) === -1;
181+
});
190182

191183
/**
192184
* Helper to resolve comma separated lists of file pattern strings relative to

lib/config.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ export interface Config {
595595
*/
596596
ng12Hybrid?: boolean;
597597

598-
seleniumArgs?: Array<any>;
598+
/**
599+
* Protractor will exit with an error if it sees any command line flags it doesn't
600+
* recognize. Set disableChecks true to disable this check.
601+
*/
602+
disableChecks?: boolean;
603+
604+
seleniumArgs?: any[];
599605
jvmArgs?: string[];
600606
configDir?: string;
601607
troubleshoot?: boolean;
@@ -607,4 +613,5 @@ export interface Config {
607613
frameworkPath?: string;
608614
elementExplorer?: any;
609615
debug?: boolean;
616+
unknownFlags_?: string[];
610617
}

lib/frameworks/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Requirements
3737

3838
- `runner.runTestPreparer` must be called after the framework has been
3939
initialized but before any spec files are run. This function returns a
40-
promise which should be waited on before executing tests.
40+
promise which should be waited on before executing tests. The framework should
41+
also pass an array of extra command line flags it accepts, if any.
4142

4243
- `runner.getConfig().onComplete` must be called when tests are finished.
4344
It might return a promise, in which case `exports.run`'s promise should not

lib/runner.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as util from 'util';
66
import {ProtractorBrowser} from './browser';
77
import {Config} from './config';
88
import {buildDriverProvider, DriverProvider} from './driverProviders';
9+
import {ConfigError} from './exitCodes';
910
import {Logger} from './logger';
1011
import {Plugins} from './plugins';
1112
import {protractor} from './ptor';
@@ -79,10 +80,21 @@ export class Runner extends EventEmitter {
7980
/**
8081
* Executor of testPreparer
8182
* @public
83+
* @param {string[]=} An optional list of command line arguments the framework will accept.
8284
* @return {q.Promise} A promise that will resolve when the test preparers
8385
* are finished.
8486
*/
85-
runTestPreparer(): q.Promise<any> {
87+
runTestPreparer(extraFlags?: string[]): q.Promise<any> {
88+
let unknownFlags = this.config_.unknownFlags_ || [];
89+
if (extraFlags) {
90+
unknownFlags = unknownFlags.filter((f) => extraFlags.indexOf(f) === -1);
91+
}
92+
if (unknownFlags.length > 0 && !this.config_.disableChecks) {
93+
throw new ConfigError(
94+
logger,
95+
'Found extra flags: ' + unknownFlags.join(', ') +
96+
', please use --disableChecks flag to disable the Protractor CLI flag checks. ');
97+
}
8698
return this.plugins_.onPrepare().then(() => {
8799
return helper.runFilenameOrFn_(this.config_.configDir, this.preparer_);
88100
});

scripts/errorTest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var checkLogs = function(output, messages) {
2121

2222
runProtractor = spawn('node',
2323
['bin/protractor', 'example/conf.js', '--foobar', 'foobar']);
24-
output = runProtractor.stderr.toString();
24+
output = runProtractor.stdout.toString();
2525
messages = ['Error: Found extra flags: foobar'];
2626
checkLogs(output, messages);
2727

0 commit comments

Comments
 (0)