Skip to content

Commit

Permalink
feat(max_versions): set max versions based on string matching
Browse files Browse the repository at this point in the history
- Do a version match based on string startsWith of the maxVersion
  An example:

  Matching "0.1" might find versions 0.14.0, 0.151.0, 0.1.0. It will then
  get the max version which is 0.151. If a user wanted to get 0.1, then
  they could specify version "0.1."

- Fix / update interchangable aliases:
  - selenium == standalone
  - chromedriver == chrome
  - geckodriver == gecko
  - iedriver = ie

Tagging angular#280, angular#358, angular#353. Additional work is still required to have a
config file that has this information instead of hard coding it.
  • Loading branch information
cnishina committed Apr 24, 2019
1 parent 289d183 commit 7ad7b6d
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 122 deletions.
135 changes: 98 additions & 37 deletions lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import * as start from '../cmds/start';
import * as status from '../cmds/status';
import * as update from '../cmds/update';

const CHROME = 'chrome';
const chromeOption: yargs.Options = {
const CHROMEDRIVER_ALIAS = 'chrome';
const CHROMEDRIVER = 'chromedriver';
const chromedriverOption: yargs.Options = {
describe: 'Install or update chromedriver.',
default: true,
type: 'boolean'
};
const CHROME_LOGS = 'chrome_logs';
const chromeLogsOption: yargs.Options = {
const CHROMEDRIVER_LOGS_ALIAS = 'chrome_logs';
const CHROMEDRIVER_LOGS = 'chromedriver_logs';
const chromedriverLogsOption: yargs.Options = {
describe: 'File path to chrome logs.',
type: 'string'
};
Expand All @@ -30,8 +32,9 @@ const edgeOption: yargs.Options = {
'"C:\Program Files (x86)\Microsoft Web Driver\MirosoftWebDriver.exe"',
type: 'string'
};
const GECKO = 'gecko';
const geckoOption: yargs.Options = {
const GECKODRIVER_ALIAS = 'gecko';
const GECKODRIVER = 'geckodriver';
const geckodriverOption: yargs.Options = {
describe: 'Install or update geckodriver.',
default: true,
type: 'boolean'
Expand All @@ -41,8 +44,9 @@ const githubTokenOption: yargs.Options = {
describe: 'Use a GitHub token to prevent rate limit issues.',
type: 'string'
};
const IEDRIVER_ALIAS = 'ie';
const IEDRIVER = 'iedriver';
const ieOption: yargs.Options = {
const iedriverOption: yargs.Options = {
describe: 'Install or update ie driver.',
default: false,
type: 'boolean'
Expand All @@ -58,6 +62,31 @@ const logLevelOption: yargs.Options = {
default: 'info',
type: 'string'
};
const MAX_VERSIONS_CHROMEDRIVER_ALIAS = 'max_versions.chrome';
const MAX_VERSIONS_CHROMEDRIVER = 'max_versions.chromedriver';
const maxVersionsChromedriverOption: yargs.Options = {
describe: 'The chromedriver max version used only for update.',
type: 'string'
};
const MAX_VERSIONS_GECKODRIVER_ALIAS = 'max_versions.gecko';
const MAX_VERSIONS_GECKODRIVER = 'max_versions.geckodriver';
const maxVersionsGeckodriverOption: yargs.Options = {
describe: 'The geckodriver max version used only for update.',
type: 'string'
};
const MAX_VERSIONS_IEDRIVER_ALIAS = 'max_versions.ie';
const MAX_VERSIONS_IEDRIVER = 'max_versions.iedriver';
const maxVersionsIedriverOption: yargs.Options = {
describe: 'The ie driver max version used only for update.',
type: 'string'
};
const MAX_VERSIONS_SELENIUM_ALIAS = 'max_versions.standalone';
const MAX_VERSIONS_SELENIUM = 'max_versions.selenium';
const maxVersionsSeleniumOption: yargs.Options = {
describe: 'The selenium server standalone max version used only for update.',
type: 'string'
};

const OUT_DIR = 'out_dir';
const outDirOption: yargs.Options = {
describe: 'Location of output.',
Expand All @@ -68,34 +97,40 @@ const proxyOption: yargs.Options = {
describe: 'Use a proxy server to download files.',
type: 'string'
};
const STANDALONE = 'standalone';
const standaloneOption: yargs.Options = {
const SELENIUM_ALIAS = 'standalone';
const SELENIUM = 'selenium';
const seleniumOption: yargs.Options = {
describe: 'Install or update selenium server standalone.',
default: true,
type: 'boolean'
};
const STANDALONE_NODE = 'standalone_node';
const standaloneNodeOption: yargs.Options = {
const SELENIUM_NODE_ALIAS = 'standalone_node';
const SELENIUM_NODE = 'selenium_node';
const seleniumNodeOption: yargs.Options = {
describe: 'Start the selenium server standalone with role set to "node".',
type: 'boolean'
};
const VERSIONS_CHROME = 'versions.chrome';
const versionsChromeOption: yargs.Options = {
const VERSIONS_CHROMEDRIVER_ALIAS = 'versions.chrome';
const VERSIONS_CHROMEDRIVER = 'versions.chromedriver';
const versionsChromedriverOption: yargs.Options = {
describe: 'The chromedriver version.',
type: 'string'
};
const VERSIONS_GECKO = 'versions.gecko';
const versionsGeckoOption: yargs.Options = {
const VERSIONS_GECKODRIVER_ALIAS = 'versions.gecko';
const VERSIONS_GECKODRIVER = 'versions.geckodriver';
const versionsGeckodriverOption: yargs.Options = {
describe: 'The geckodriver version.',
type: 'string'
};
const VERSIONS_IE = 'versions.ie';
const versionsIeOption: yargs.Options = {
const VERSIONS_IEDRIVER_ALIAS = 'versions.ie';
const VERSIONS_IEDRIVER = 'versions.iedriver';
const versionsIedriverOption: yargs.Options = {
describe: 'The ie driver version.',
type: 'string'
};
const VERSIONS_STANDALONE = 'versions.standalone';
const versionsStandaloneOption: yargs.Options = {
const VERSIONS_SELENIUM_ALIAS = 'versions.standalone';
const VERSIONS_SELENIUM = 'versions.selenium';
const versionsSeleniumOption: yargs.Options = {
describe: 'The selenium server standalone version.',
type: 'string'
};
Expand All @@ -122,20 +157,31 @@ yargs
.command(
'start', 'Start up the selenium server.',
(yargs: yargs.Argv) => {
return yargs.option(CHROME, chromeOption)
.option(CHROME_LOGS, chromeLogsOption)
return yargs
.option(CHROMEDRIVER, chromedriverOption)
.alias(CHROMEDRIVER_ALIAS, CHROMEDRIVER)
.option(CHROMEDRIVER_LOGS, chromedriverLogsOption)
.alias(CHROMEDRIVER_LOGS_ALIAS, CHROMEDRIVER_LOGS)
.option(DETACH, detachOption)
.option(EDGE, edgeOption)
.option(GECKO, geckoOption)
.option(IEDRIVER, ieOption)
.option(GECKODRIVER, geckodriverOption)
.alias(GECKODRIVER_ALIAS, GECKODRIVER)
.option(IEDRIVER, iedriverOption)
.alias(IEDRIVER_ALIAS, IEDRIVER)
.option(LOG_LEVEL, logLevelOption)
.option(OUT_DIR, outDirOption)
.option(STANDALONE, standaloneOption)
.option(STANDALONE_NODE, standaloneNodeOption)
.option(VERSIONS_CHROME, versionsChromeOption)
.option(VERSIONS_GECKO, versionsGeckoOption)
.option(VERSIONS_IE, versionsIeOption)
.option(VERSIONS_STANDALONE, versionsStandaloneOption);
.option(SELENIUM, seleniumOption)
.alias(SELENIUM_ALIAS, SELENIUM)
.option(SELENIUM_NODE, seleniumNodeOption)
.alias(SELENIUM_NODE_ALIAS, SELENIUM_NODE)
.option(VERSIONS_CHROMEDRIVER, versionsChromedriverOption)
.alias(VERSIONS_CHROMEDRIVER_ALIAS, VERSIONS_CHROMEDRIVER)
.option(VERSIONS_GECKODRIVER, versionsGeckodriverOption)
.alias(VERSIONS_GECKODRIVER_ALIAS, VERSIONS_GECKODRIVER)
.option(VERSIONS_IEDRIVER, versionsIedriverOption)
.alias(VERSIONS_IEDRIVER_ALIAS, VERSIONS_IEDRIVER)
.option(VERSIONS_SELENIUM, versionsSeleniumOption)
.alias(VERSIONS_SELENIUM_ALIAS, VERSIONS_SELENIUM);
},
(argv: yargs.Arguments) => {
start.handler(argv);
Expand All @@ -153,19 +199,34 @@ yargs
'update', 'Install or update selected binaries.',
(yargs: yargs.Argv) => {
return yargs.option(OUT_DIR, outDirOption)
.option(CHROME, chromeOption)
.option(GECKO, geckoOption)
.option(CHROMEDRIVER, chromedriverOption)
.alias(CHROMEDRIVER_ALIAS, CHROMEDRIVER)
.option(GECKODRIVER, geckodriverOption)
.alias(GECKODRIVER_ALIAS, GECKODRIVER)
.option(GITHUB_TOKEN, githubTokenOption)
.option(IEDRIVER, ieOption)
.option(IEDRIVER, iedriverOption)
.alias(IEDRIVER_ALIAS, IEDRIVER)
.option(IGNORE_SSL, ignoreSSLOption)
.option(LOG_LEVEL, logLevelOption)
.option(MAX_VERSIONS_CHROMEDRIVER, maxVersionsChromedriverOption)
.alias(MAX_VERSIONS_CHROMEDRIVER_ALIAS, MAX_VERSIONS_CHROMEDRIVER)
.option(MAX_VERSIONS_GECKODRIVER, maxVersionsGeckodriverOption)
.alias(MAX_VERSIONS_GECKODRIVER_ALIAS, MAX_VERSIONS_GECKODRIVER)
.option(MAX_VERSIONS_IEDRIVER, maxVersionsIedriverOption)
.alias(MAX_VERSIONS_IEDRIVER_ALIAS, MAX_VERSIONS_IEDRIVER)
.option(MAX_VERSIONS_SELENIUM, maxVersionsSeleniumOption)
.option(OUT_DIR, outDirOption)
.option(PROXY, proxyOption)
.option(STANDALONE, standaloneOption)
.option(VERSIONS_CHROME, versionsChromeOption)
.option(VERSIONS_GECKO, versionsGeckoOption)
.option(VERSIONS_IE, versionsIeOption)
.option(VERSIONS_STANDALONE, versionsStandaloneOption);
.option(SELENIUM, seleniumOption)
.alias(SELENIUM_ALIAS, SELENIUM)
.option(VERSIONS_CHROMEDRIVER, versionsChromedriverOption)
.alias(VERSIONS_CHROMEDRIVER_ALIAS, VERSIONS_CHROMEDRIVER)
.option(VERSIONS_GECKODRIVER, versionsGeckodriverOption)
.alias(VERSIONS_GECKODRIVER_ALIAS, VERSIONS_GECKODRIVER)
.option(VERSIONS_IEDRIVER, versionsIedriverOption)
.alias(VERSIONS_IEDRIVER_ALIAS, VERSIONS_IEDRIVER)
.option(VERSIONS_SELENIUM, versionsSeleniumOption)
.alias(VERSIONS_SELENIUM_ALIAS, VERSIONS_SELENIUM);
},
(argv: yargs.Arguments) => {
update.handler(argv);
Expand Down
8 changes: 7 additions & 1 deletion lib/cmds/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ export interface Options {
githubToken?: string;
}

export type BrowserDriverName = 'chromedriver'|'geckodriver'|'iedriver';

/**
* Contains information about a browser driver.
*/
export interface BrowserDriver {
// The name of the browser driver.
name?: 'chromedriver'|'geckodriver'|'iedriver';
name?: BrowserDriverName;
// The version which does not have to follow semver.
version?: string;
// A max version that either fully or partially matches the version.
maxVersion?: string;
}

/**
Expand All @@ -35,6 +39,8 @@ export interface Server {
name?: 'selenium';
// The version which does not have to follow semver.
version?: string;
// A max version that either fully or partially matches the version.
maxVersion?: string;
// Run as role = node option.
runAsNode?: boolean;
// The relative or full path to the chrome logs file.
Expand Down
8 changes: 5 additions & 3 deletions lib/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const log = loglevel.getLogger('webdriver-manager');
* @param argv The argv from yargs.
*/
export async function handler(argv: yargs.Arguments) {
log.setLevel(argv.log_level);
log.setLevel(argv['log_level']);
const options = convertArgs2Options(argv);
await update(options);
}
Expand All @@ -35,12 +35,14 @@ export function updateBinary(optionsBinary: OptionsBinary): Promise<void[]> {
const promises = [];
if (optionsBinary.browserDrivers) {
for (const provider of optionsBinary.browserDrivers) {
promises.push(provider.binary.updateBinary(provider.version));
promises.push(provider.binary.updateBinary(provider.version,
provider.maxVersion));
}
}
if (optionsBinary.server && optionsBinary.server.binary) {
promises.push(
optionsBinary.server.binary.updateBinary(optionsBinary.server.version));
optionsBinary.server.binary.updateBinary(optionsBinary.server.version,
optionsBinary.server.maxVersion));
}
return Promise.all(promises);
}
24 changes: 5 additions & 19 deletions lib/cmds/utils.spec-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,16 @@ describe('utils', () => {
const argv = {
_: ['foobar'],
proxy: 'http://some.proxy.com',
versions: {gecko: '0.16.0', chrome: '2.20'},
versions: {geckodriver: '0.16.0', chromedriver: '2.20'},
out_dir: 'foobar_download',
ignore_ssl: false,
'$0': 'bin\\webdriver-manager'
};
const options = convertArgs2AllOptions(argv);
expect(options.browserDrivers).toBeTruthy();
expect(options.browserDrivers.length).toBe(3);
for (const provider of options.browserDrivers) {
if (provider.name === 'geckodriver') {
expect(provider.version).toBe('0.16.0');
}
if (provider.name === 'chromedriver') {
expect(provider.version).toBe('2.20');
}
if (provider.name === 'iedriver') {
expect(provider.version).toBeUndefined();
}
}
expect(options.server).toBeTruthy();
expect(options.server.name).toBe('selenium');
expect(options.server.version).toBeUndefined();
expect(options.proxy).toBe('http://some.proxy.com');
expect(options.ignoreSSL).toBeFalsy();
expect(options.outDir).toBe('foobar_download');
});
});
Expand All @@ -38,10 +24,10 @@ describe('utils', () => {
it('should create the default providers', () => {
const argv = {
_: ['foobar'],
chrome: true,
gecko: true,
standalone: true,
versions: {gecko: '0.16.0', chrome: '2.20'},
chromedriver: true,
geckodriver: true,
selenium: true,
versions: {geckodriver: '0.16.0', chromedriver: '2.20'},
out_dir: 'foobar_download',
'$0': 'bin\\webdriver-manager'
};
Expand Down
Loading

0 comments on commit 7ad7b6d

Please sign in to comment.