Skip to content

Commit f6c78e8

Browse files
Add --standalone flag for Android setup (#27)
Co-authored-by: Priyansh Garg <[email protected]>
1 parent 9caa6b8 commit f6c78e8

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

src/commands/android/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const AVAILABLE_OPTIONS: AvailableOptions = {
2424
appium: {
2525
alias: [],
2626
description: 'Make sure the final setup works with Appium out-of-the-box.'
27+
},
28+
standalone: {
29+
alias: [],
30+
description: 'Do standalone setup for Android Emulator (no Nightwatch-related requirements will be downloaded).'
2731
}
2832
};
2933

src/commands/android/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ export class AndroidSetup {
415415
}
416416
}
417417

418+
// For standalone mode, don't ask the browser question (set `configs.browsers` to 'none').
419+
// But if a user explicitly provides a browser using the `--browsers` flag, use it.
420+
if (options.standalone && !configs.browsers) {
421+
configs.browsers = 'none';
422+
423+
// if just the `--browsers` flag is passed with no argument,
424+
// ask the browser question even in the case of standalone.
425+
if (options.browsers === true) {
426+
delete configs.browsers;
427+
}
428+
}
429+
418430
return configs;
419431
}
420432

@@ -858,12 +870,14 @@ export class AndroidSetup {
858870

859871
// TODO: add major version of Chrome as suffix to chromedriver.
860872
// Or, check the version of existing chromedriver using --version.
861-
Logger.log('Checking if chromedriver is already downloaded...');
862-
if (fs.existsSync(chromedriverDownloadPath)) {
863-
Logger.log(` ${colors.green(symbols().ok)} chromedriver already present at '${chromedriverDownloadPath}'\n`);
864-
} else {
865-
Logger.log(` ${colors.red(symbols().fail)} chromedriver not found at '${chromedriverDownloadPath}'\n`);
866-
downloadChromedriver = true;
873+
if (!this.options.standalone) {
874+
Logger.log('Checking if chromedriver is already downloaded...');
875+
if (fs.existsSync(chromedriverDownloadPath)) {
876+
Logger.log(` ${colors.green(symbols().ok)} chromedriver already present at '${chromedriverDownloadPath}'\n`);
877+
} else {
878+
Logger.log(` ${colors.red(symbols().fail)} chromedriver not found at '${chromedriverDownloadPath}'\n`);
879+
downloadChromedriver = true;
880+
}
867881
}
868882
} else if (stdout !== null) {
869883
Logger.log(` ${colors.red(symbols().fail)} Chrome browser not found in the AVD.\n`);

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const run = () => {
99
try {
1010
const argv = process.argv.slice(2);
1111
const {_: args, ...options} = minimist(argv, {
12-
boolean: ['install', 'setup', 'help', 'appium'],
12+
boolean: ['install', 'setup', 'help', 'appium', 'standalone'],
1313
alias: {
1414
help: 'h',
1515
mode: 'm',

tests/unit_tests/commands/android/testIndex.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,25 @@ describe('test getConfigFromOptions', function() {
440440

441441
configs = androidSetup.getConfigFromOptions({mode: true, browsers: []});
442442
assert.deepStrictEqual(configs, {});
443+
444+
configs = androidSetup.getConfigFromOptions({standalone: true});
445+
assert.deepStrictEqual(configs, {browsers: 'none'});
446+
447+
configs = androidSetup.getConfigFromOptions({standalone: true, browsers: false});
448+
assert.deepStrictEqual(configs, {browsers: 'none'});
449+
450+
// if just `--browsers` option is passed with no argument, ask the browsers question.
451+
configs = androidSetup.getConfigFromOptions({standalone: true, browsers: true});
452+
assert.deepStrictEqual(configs, {});
453+
454+
configs = androidSetup.getConfigFromOptions({standalone: true, browsers: 'chrome'});
455+
assert.deepStrictEqual(configs, {browsers: 'chrome'});
456+
457+
configs = androidSetup.getConfigFromOptions({standalone: true, browsers: 'chrome,firefox'});
458+
assert.deepStrictEqual(configs, {browsers: 'both'});
459+
460+
configs = androidSetup.getConfigFromOptions({standalone: true, browsers: 'brave'});
461+
assert.deepStrictEqual(configs, {browsers: 'none'});
443462
});
444463
});
445464

0 commit comments

Comments
 (0)