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

fix(cli): Allow frameworks to specify extra command line flags #3994

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,10 @@ if (argv.version) {
process.exit(0);
}

if (!argv.disableChecks) {
// Check to see if additional flags were used.
let unknownKeys: string[] = Object.keys(argv).filter((element: string) => {
return element !== '$0' && element !== '_' && allowedNames.indexOf(element) === -1;
});

if (unknownKeys.length > 0) {
throw new Error(
'Found extra flags: ' + unknownKeys.join(', ') +
', please use --disableChecks flag to disable the Protractor CLI flag checks.');
}
}
// Check to see if additional flags were used.
argv.unknownFlags_ = Object.keys(argv).filter((element: string) => {
return element !== '$0' && element !== '_' && allowedNames.indexOf(element) === -1;
});

/**
* Helper to resolve comma separated lists of file pattern strings relative to
Expand Down
9 changes: 8 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,13 @@ export interface Config {
*/
ng12Hybrid?: boolean;

seleniumArgs?: Array<any>;
/**
* Protractor will exit with an error if it sees any command line flags it doesn't
* recognize. Set disableChecks true to disable this check.
*/
disableChecks?: boolean;

seleniumArgs?: any[];
jvmArgs?: string[];
configDir?: string;
troubleshoot?: boolean;
Expand All @@ -607,4 +613,5 @@ export interface Config {
frameworkPath?: string;
elementExplorer?: any;
debug?: boolean;
unknownFlags_?: string[];
}
3 changes: 2 additions & 1 deletion lib/frameworks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Requirements

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

- `runner.getConfig().onComplete` must be called when tests are finished.
It might return a promise, in which case `exports.run`'s promise should not
Expand Down
14 changes: 13 additions & 1 deletion lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as util from 'util';
import {ProtractorBrowser} from './browser';
import {Config} from './config';
import {buildDriverProvider, DriverProvider} from './driverProviders';
import {ConfigError} from './exitCodes';
import {Logger} from './logger';
import {Plugins} from './plugins';
import {protractor} from './ptor';
Expand Down Expand Up @@ -79,10 +80,21 @@ export class Runner extends EventEmitter {
/**
* Executor of testPreparer
* @public
* @param {string[]=} An optional list of command line arguments the framework will accept.
* @return {q.Promise} A promise that will resolve when the test preparers
* are finished.
*/
runTestPreparer(): q.Promise<any> {
runTestPreparer(extraFlags?: string[]): q.Promise<any> {
let unknownFlags = this.config_.unknownFlags_ || [];
if (extraFlags) {
unknownFlags = unknownFlags.filter((f) => extraFlags.indexOf(f) === -1);
Copy link
Member

@cnishina cnishina Jan 21, 2017

Choose a reason for hiding this comment

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

Yup I stand corrected. This should be ===. Filter flags that do not exist in extra flags. LGTM.

}
if (unknownFlags.length > 0 && !this.config_.disableChecks) {
throw new ConfigError(
logger,
'Found extra flags: ' + unknownFlags.join(', ') +
', please use --disableChecks flag to disable the Protractor CLI flag checks. ');
}
return this.plugins_.onPrepare().then(() => {
return helper.runFilenameOrFn_(this.config_.configDir, this.preparer_);
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/errorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var checkLogs = function(output, messages) {

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

Expand Down