Skip to content

feat(max_versions): set max versions based on string matching #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2019
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
137 changes: 99 additions & 38 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 @@ -79,34 +108,40 @@ const seleniumLogLevelOption: yargs.Options = {
describe: 'Set the -Dselenium.LOGGER.level flag when starting the server',
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 @@ -133,22 +168,33 @@ 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(SELENIUM_PORT, seleniumPort)
.option(SELENIUM, seleniumOption)
.alias(SELENIUM_ALIAS, SELENIUM)
.option(SELENIUM_LOG_LEVEL, seleniumLogLevelOption)
.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_NODE, seleniumNodeOption)
.alias(SELENIUM_NODE_ALIAS, SELENIUM_NODE)
.option(SELENIUM_PORT, seleniumPort)
.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 @@ -166,19 +212,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
14 changes: 7 additions & 7 deletions lib/cmds/cmds.spec-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('using the cli', () => {
it('should download the files', async () => {
const argv = {
_: ['foobar'],
chrome: true,
standalone: true,
chromedriver: true,
selenium: true,
out_dir: tmpDir,
'$0': 'bin\\webdriver-manager'
};
Expand Down Expand Up @@ -70,9 +70,9 @@ describe('using the cli', () => {
it('should start the selenium server standalone in role=node', async () => {
const argv = {
_: ['foobar'],
chrome: true,
standalone: true,
standalone_node: true,
chromedriver: true,
selenium: true,
selenium_node: true,
out_dir: tmpDir,
'$0': 'bin\\webdriver-manager'
};
Expand Down Expand Up @@ -104,8 +104,8 @@ describe('using the cli', () => {
it('should start the selenium server standalone', async () => {
const argv = {
_: ['foobar'],
chrome: true,
standalone: true,
chromedriver: true,
selenium: true,
out_dir: tmpDir,
'$0': 'bin\\webdriver-manager'
};
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