This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore(typescript): convert cli.js to cli.ts #3151
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,149 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as optimist from 'optimist'; | ||
|
||
/** | ||
* The command line interface for interacting with the Protractor runner. | ||
* It takes care of parsing command line options. | ||
* | ||
* Values from command line options override values from the config. | ||
*/ | ||
|
||
var args: Array<string> = []; | ||
|
||
process.argv.slice(2).forEach(function(arg: string) { | ||
var flag: string = arg.split('=')[0]; | ||
|
||
switch (flag) { | ||
case 'debug': | ||
args.push('--nodeDebug'); | ||
args.push('true'); | ||
break; | ||
case '-d': | ||
case '--debug': | ||
case '--debug-brk': | ||
args.push('--v8Debug'); | ||
args.push('true'); | ||
break; | ||
default: | ||
args.push(arg); | ||
break; | ||
} | ||
}); | ||
|
||
optimist | ||
.usage( | ||
'Usage: protractor [configFile] [options]\n' + | ||
'configFile defaults to protractor.conf.js\n' + | ||
'The [options] object will override values from the config file.\n' + | ||
'See the reference config for a full list of options.') | ||
.describe('help', 'Print Protractor help menu') | ||
.describe('version', 'Print Protractor version') | ||
.describe('browser', 'Browsername, e.g. chrome or firefox') | ||
.describe('seleniumAddress', 'A running selenium address to use') | ||
.describe('seleniumSessionId', 'Attaching an existing session id') | ||
.describe( | ||
'seleniumServerJar', 'Location of the standalone selenium jar file') | ||
.describe( | ||
'seleniumPort', 'Optional port for the selenium standalone server') | ||
.describe('baseUrl', 'URL to prepend to all relative paths') | ||
.describe('rootElement', 'Element housing ng-app, if not html or body') | ||
.describe('specs', 'Comma-separated list of files to test') | ||
.describe('exclude', 'Comma-separated list of files to exclude') | ||
.describe('verbose', 'Print full spec names') | ||
.describe('stackTrace', 'Print stack trace on error') | ||
.describe('params', 'Param object to be passed to the tests') | ||
.describe('framework', 'Test framework to use: jasmine, mocha, or custom') | ||
.describe('resultJsonOutputFile', 'Path to save JSON test result') | ||
.describe('troubleshoot', 'Turn on troubleshooting output') | ||
.describe('elementExplorer', 'Interactively test Protractor commands') | ||
.describe( | ||
'debuggerServerPort', | ||
'Start a debugger server at specified port instead of repl') | ||
.alias('browser', 'capabilities.browserName') | ||
.alias('name', 'capabilities.name') | ||
.alias('platform', 'capabilities.platform') | ||
.alias('platform-version', 'capabilities.version') | ||
.alias('tags', 'capabilities.tags') | ||
.alias('build', 'capabilities.build') | ||
.alias('grep', 'jasmineNodeOpts.grep') | ||
.alias('invert-grep', 'jasmineNodeOpts.invertGrep') | ||
.alias('explorer', 'elementExplorer') | ||
.string('capabilities.tunnel-identifier') | ||
.check(function(arg: any) { | ||
if (arg._.length > 1) { | ||
throw 'Error: more than one config file specified'; | ||
} | ||
}); | ||
|
||
var argv: any = optimist.parse(args); | ||
|
||
if (argv.help) { | ||
optimist.showHelp(); | ||
process.exit(0); | ||
} | ||
|
||
if (argv.version) { | ||
console.log( | ||
'Version ' + require(path.join(__dirname, '../package.json')).version); | ||
process.exit(0); | ||
} | ||
|
||
// WebDriver capabilities properties require dot notation, but optimist parses | ||
// that into an object. Re-flatten it. | ||
function flattenObject(obj: any, prefix?: string, out?: any): any { | ||
prefix = prefix || ''; | ||
out = out || {}; | ||
for (var prop in obj) { | ||
if (obj.hasOwnProperty(prop)) { | ||
typeof obj[prop] === 'object' ? | ||
flattenObject(obj[prop], prefix + prop + '.', out) : | ||
out[prefix + prop] = obj[prop]; | ||
} | ||
} | ||
return out; | ||
}; | ||
|
||
if (argv.capabilities) { | ||
argv.capabilities = flattenObject(argv.capabilities); | ||
} | ||
|
||
/** | ||
* Helper to resolve comma separated lists of file pattern strings relative to | ||
* the cwd. | ||
* | ||
* @private | ||
* @param {Array} list | ||
*/ | ||
function processFilePatterns_(list: string): Array<string> { | ||
return list.split(',').map(function(spec) { | ||
return path.resolve(process.cwd(), spec); | ||
}); | ||
}; | ||
|
||
if (argv.specs) { | ||
argv.specs = processFilePatterns_(<string>argv.specs); | ||
} | ||
if (argv.exclude) { | ||
argv.exclude = processFilePatterns_(<string>argv.exclude); | ||
} | ||
|
||
// Use default configuration, if it exists. | ||
var configFile: string = argv._[0]; | ||
if (!configFile) { | ||
if (fs.existsSync('./protractor.conf.js')) { | ||
configFile = './protractor.conf.js'; | ||
} | ||
} | ||
|
||
if (!configFile && !argv.elementExplorer && args.length < 3) { | ||
console.log( | ||
'**you must either specify a configuration file ' + | ||
'or at least 3 options. See below for the options:\n'); | ||
optimist.showHelp(); | ||
process.exit(1); | ||
} | ||
|
||
// Run the launcher | ||
import * as launcher from './launcher'; | ||
launcher.init(configFile, argv); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should move the import to the top of the file.