Skip to content

Commit 72e3d9f

Browse files
authored
feat(status): show the last downloaded version when using status (#177)
- added a test to run update, then checks status for labels closes #172
1 parent b40a93f commit 72e3d9f

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed

lib/cmds/initialize.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ export function android(
245245
'android-sdk: Downloading more additional SDK updates ' +
246246
'(this may take a while)');
247247
return downloadAndroidUpdates(
248-
sdkPath, ['build-tools-24.0.0'].concat(
249-
getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)),
248+
sdkPath,
249+
['build-tools-24.0.0'].concat(
250+
getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)),
250251
true, acceptLicenses, verbose);
251252
})
252253
.then(() => {

lib/cmds/opts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ opts[STARTED_SIGNIFIER] = new Option(
105105
'A string to be outputted once the selenium server is up and running. Useful if you are writing a script which uses webdriver-manager.',
106106
'string');
107107
opts[SIGNAL_VIA_IPC] = new Option(
108-
SIGNAL_VIA_IPC, 'If you are using --' + STARTED_SIGNIFIER +
108+
SIGNAL_VIA_IPC,
109+
'If you are using --' + STARTED_SIGNIFIER +
109110
', this flag will emit the signal string using process.send(), rather than writing it to stdout',
110111
'boolean', false);
111112
opts[DETACH] = new Option(

lib/cmds/status.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as minimist from 'minimist';
33
import * as path from 'path';
44

5+
import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, StandAlone} from '../binaries';
56
import {Logger, Options, Program} from '../cli';
67
import {Config} from '../config';
78
import {FileManager} from '../files';
@@ -49,19 +50,51 @@ function status(options: Options) {
4950
return;
5051
}
5152

53+
// Try to get the update-config.json. This will be used for showing the last binary downloaded.
54+
let updateConfig: any = {};
55+
try {
56+
updateConfig =
57+
JSON.parse(fs.readFileSync(path.resolve(outputDir, 'update-config.json')).toString()) || {};
58+
} catch (err) {
59+
updateConfig = {};
60+
}
61+
5262

5363
let downloadedBinaries = FileManager.downloadedBinaries(outputDir);
54-
// log which binaries have been downloaded
64+
// Log which binaries have been downloaded.
5565
for (let bin in downloadedBinaries) {
5666
let downloaded = downloadedBinaries[bin];
5767
let log = downloaded.name + ' ';
5868
log += downloaded.versions.length == 1 ? 'version available: ' : 'versions available: ';
69+
70+
// Get the "last" downloaded binary from the updateConfig.
71+
let last: string = null;
72+
if (downloaded.binary instanceof Appium && updateConfig[Appium.id]) {
73+
last = updateConfig[Appium.id]['last'];
74+
} else if (downloaded.binary instanceof AndroidSDK && updateConfig[AndroidSDK.id]) {
75+
last = updateConfig[AndroidSDK.id]['last'];
76+
} else if (downloaded.binary instanceof ChromeDriver && updateConfig[ChromeDriver.id]) {
77+
last = updateConfig[ChromeDriver.id]['last'];
78+
} else if (downloaded.binary instanceof GeckoDriver && updateConfig[GeckoDriver.id]) {
79+
last = updateConfig[GeckoDriver.id]['last'];
80+
} else if (downloaded.binary instanceof IEDriver && updateConfig[IEDriver.id]) {
81+
last = updateConfig[IEDriver.id]['last'];
82+
} else if (downloaded.binary instanceof StandAlone && updateConfig[StandAlone.id]) {
83+
last = updateConfig[StandAlone.id]['last'];
84+
}
85+
86+
// Log the versions:
87+
// - default: the file associated with the config.json
88+
// - last: the last binary downloaded by webdriver-manager per the update-config.json
5989
for (let ver in downloaded.versions) {
6090
let version = downloaded.versions[ver];
6191
log += version;
6292
if (downloaded.binary.versionDefault() === version) {
6393
log += ' [default]';
6494
}
95+
if (last && last.indexOf(version) >= 0) {
96+
log += ' [last]'
97+
}
6598
if (+ver != downloaded.versions.length - 1) {
6699
log += ', ';
67100
}

lib/cmds/update.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function update(options: Options): Promise<void> {
167167
let sdk_path = path.resolve(outputDir, binary.executableFilename(Config.osType()));
168168
let oldAVDList: string;
169169

170+
updateBrowserFile(binary, outputDir);
170171
promises.push(q.nfcall(fs.readFile, path.resolve(sdk_path, 'available_avds.json'))
171172
.then(
172173
(oldAVDs: string) => {
@@ -190,6 +191,7 @@ function update(options: Options): Promise<void> {
190191
checkIOS(logger);
191192
}
192193
if (android || ios) {
194+
updateBrowserFile(binaries[Appium.id], outputDir);
193195
installAppium(binaries[Appium.id], outputDir);
194196
}
195197

spec/cmds/status_spec.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as path from 'path';
2+
3+
import {Logger, WriteTo} from '../../lib/cli/logger';
4+
import {program} from '../../lib/cmds/update';
5+
import {Config} from '../../lib/config';
6+
import {spawnSync} from '../../lib/utils';
7+
8+
function getVersions(line: string): string[] {
9+
return line.split(':')[3].split(',');
10+
}
11+
12+
describe('status', () => {
13+
Logger.writeTo = WriteTo.NONE;
14+
let argv: any;
15+
let tmpDir = path.resolve('selenium_test');
16+
17+
// chrome 2.20[last], 2.24
18+
// geckodriver {{config version}} [last] [default]
19+
// standalone 2.24 [last], {{config version}} [default]
20+
beforeAll((done) => {
21+
Config.osType_ = 'Linux';
22+
Config.osArch_ = 'x64';
23+
argv = {
24+
'_': ['update'],
25+
'versions': {'chrome': '2.24', 'standalone': '2.44.0'},
26+
'out_dir': tmpDir
27+
};
28+
program.run(JSON.parse(JSON.stringify(argv)))
29+
.then(() => {
30+
argv['versions']['chrome'] = '2.20';
31+
program.run(JSON.parse(JSON.stringify(argv))).then(() => {
32+
done();
33+
});
34+
})
35+
.catch(err => {
36+
done.fail();
37+
});
38+
});
39+
40+
it('should show the version number of the default and latest versions', () => {
41+
let lines = spawnSync(
42+
process.execPath,
43+
['built/lib/webdriver.js', 'status', '--out_dir', 'selenium_test'], 'pipe')
44+
.output[1]
45+
.toString()
46+
.split('\n');
47+
let seleniumLine: string = null;
48+
let chromeLine: string = null;
49+
let geckodriverLine: string = null;
50+
let androidSdkLine: string = null;
51+
let appiumLine: string = null;
52+
53+
for (let line of lines) {
54+
if (line.indexOf('selenium') >= 0) {
55+
seleniumLine = line;
56+
} else if (line.indexOf('chrome') >= 0) {
57+
chromeLine = line;
58+
} else if (line.indexOf('geckodriver') >= 0) {
59+
geckodriverLine = line;
60+
} else if (line.indexOf('android-sdk') >= 0) {
61+
androidSdkLine = line;
62+
} else if (line.indexOf('appium') >= 0) {
63+
appiumLine = line;
64+
}
65+
}
66+
expect(seleniumLine).not.toBeNull();
67+
expect(seleniumLine).not.toContain('[default]')
68+
expect(getVersions(seleniumLine).length).toEqual(1);
69+
expect(getVersions(seleniumLine)[0]).toContain('2.44.0 [last]');
70+
71+
expect(chromeLine).not.toBeNull();
72+
expect(chromeLine).not.toContain('[default]');
73+
expect(getVersions(chromeLine).length).toEqual(2);
74+
expect(getVersions(chromeLine)[0]).toContain('2.20 [last]');
75+
expect(getVersions(chromeLine)[1]).toContain('2.24');
76+
77+
expect(geckodriverLine).not.toBeNull();
78+
expect(geckodriverLine).toContain('[default]');
79+
expect(geckodriverLine).toContain('[last]');
80+
expect(getVersions(geckodriverLine).length).toEqual(1);
81+
82+
expect(androidSdkLine).not.toBeNull();
83+
expect(androidSdkLine).toContain('not present');
84+
expect(appiumLine).not.toBeNull();
85+
expect(appiumLine).toContain('not present');
86+
});
87+
});

0 commit comments

Comments
 (0)