Skip to content

Commit

Permalink
feat(status): show the last downloaded version when using status (#177)
Browse files Browse the repository at this point in the history
- added a test to run update, then checks status for labels

closes #172
  • Loading branch information
cnishina authored Dec 13, 2016
1 parent b40a93f commit 72e3d9f
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/cmds/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ export function android(
'android-sdk: Downloading more additional SDK updates ' +
'(this may take a while)');
return downloadAndroidUpdates(
sdkPath, ['build-tools-24.0.0'].concat(
getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)),
sdkPath,
['build-tools-24.0.0'].concat(
getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)),
true, acceptLicenses, verbose);
})
.then(() => {
Expand Down
3 changes: 2 additions & 1 deletion lib/cmds/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ opts[STARTED_SIGNIFIER] = new Option(
'A string to be outputted once the selenium server is up and running. Useful if you are writing a script which uses webdriver-manager.',
'string');
opts[SIGNAL_VIA_IPC] = new Option(
SIGNAL_VIA_IPC, 'If you are using --' + STARTED_SIGNIFIER +
SIGNAL_VIA_IPC,
'If you are using --' + STARTED_SIGNIFIER +
', this flag will emit the signal string using process.send(), rather than writing it to stdout',
'boolean', false);
opts[DETACH] = new Option(
Expand Down
35 changes: 34 additions & 1 deletion lib/cmds/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as minimist from 'minimist';
import * as path from 'path';

import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, StandAlone} from '../binaries';
import {Logger, Options, Program} from '../cli';
import {Config} from '../config';
import {FileManager} from '../files';
Expand Down Expand Up @@ -49,19 +50,51 @@ function status(options: Options) {
return;
}

// Try to get the update-config.json. This will be used for showing the last binary downloaded.
let updateConfig: any = {};
try {
updateConfig =
JSON.parse(fs.readFileSync(path.resolve(outputDir, 'update-config.json')).toString()) || {};
} catch (err) {
updateConfig = {};
}


let downloadedBinaries = FileManager.downloadedBinaries(outputDir);
// log which binaries have been downloaded
// Log which binaries have been downloaded.
for (let bin in downloadedBinaries) {
let downloaded = downloadedBinaries[bin];
let log = downloaded.name + ' ';
log += downloaded.versions.length == 1 ? 'version available: ' : 'versions available: ';

// Get the "last" downloaded binary from the updateConfig.
let last: string = null;
if (downloaded.binary instanceof Appium && updateConfig[Appium.id]) {
last = updateConfig[Appium.id]['last'];
} else if (downloaded.binary instanceof AndroidSDK && updateConfig[AndroidSDK.id]) {
last = updateConfig[AndroidSDK.id]['last'];
} else if (downloaded.binary instanceof ChromeDriver && updateConfig[ChromeDriver.id]) {
last = updateConfig[ChromeDriver.id]['last'];
} else if (downloaded.binary instanceof GeckoDriver && updateConfig[GeckoDriver.id]) {
last = updateConfig[GeckoDriver.id]['last'];
} else if (downloaded.binary instanceof IEDriver && updateConfig[IEDriver.id]) {
last = updateConfig[IEDriver.id]['last'];
} else if (downloaded.binary instanceof StandAlone && updateConfig[StandAlone.id]) {
last = updateConfig[StandAlone.id]['last'];
}

// Log the versions:
// - default: the file associated with the config.json
// - last: the last binary downloaded by webdriver-manager per the update-config.json
for (let ver in downloaded.versions) {
let version = downloaded.versions[ver];
log += version;
if (downloaded.binary.versionDefault() === version) {
log += ' [default]';
}
if (last && last.indexOf(version) >= 0) {
log += ' [last]'
}
if (+ver != downloaded.versions.length - 1) {
log += ', ';
}
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function update(options: Options): Promise<void> {
let sdk_path = path.resolve(outputDir, binary.executableFilename(Config.osType()));
let oldAVDList: string;

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

Expand Down
87 changes: 87 additions & 0 deletions spec/cmds/status_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as path from 'path';

import {Logger, WriteTo} from '../../lib/cli/logger';
import {program} from '../../lib/cmds/update';
import {Config} from '../../lib/config';
import {spawnSync} from '../../lib/utils';

function getVersions(line: string): string[] {
return line.split(':')[3].split(',');
}

describe('status', () => {
Logger.writeTo = WriteTo.NONE;
let argv: any;
let tmpDir = path.resolve('selenium_test');

// chrome 2.20[last], 2.24
// geckodriver {{config version}} [last] [default]
// standalone 2.24 [last], {{config version}} [default]
beforeAll((done) => {
Config.osType_ = 'Linux';
Config.osArch_ = 'x64';
argv = {
'_': ['update'],
'versions': {'chrome': '2.24', 'standalone': '2.44.0'},
'out_dir': tmpDir
};
program.run(JSON.parse(JSON.stringify(argv)))
.then(() => {
argv['versions']['chrome'] = '2.20';
program.run(JSON.parse(JSON.stringify(argv))).then(() => {
done();
});
})
.catch(err => {
done.fail();
});
});

it('should show the version number of the default and latest versions', () => {
let lines = spawnSync(
process.execPath,
['built/lib/webdriver.js', 'status', '--out_dir', 'selenium_test'], 'pipe')
.output[1]
.toString()
.split('\n');
let seleniumLine: string = null;
let chromeLine: string = null;
let geckodriverLine: string = null;
let androidSdkLine: string = null;
let appiumLine: string = null;

for (let line of lines) {
if (line.indexOf('selenium') >= 0) {
seleniumLine = line;
} else if (line.indexOf('chrome') >= 0) {
chromeLine = line;
} else if (line.indexOf('geckodriver') >= 0) {
geckodriverLine = line;
} else if (line.indexOf('android-sdk') >= 0) {
androidSdkLine = line;
} else if (line.indexOf('appium') >= 0) {
appiumLine = line;
}
}
expect(seleniumLine).not.toBeNull();
expect(seleniumLine).not.toContain('[default]')
expect(getVersions(seleniumLine).length).toEqual(1);
expect(getVersions(seleniumLine)[0]).toContain('2.44.0 [last]');

expect(chromeLine).not.toBeNull();
expect(chromeLine).not.toContain('[default]');
expect(getVersions(chromeLine).length).toEqual(2);
expect(getVersions(chromeLine)[0]).toContain('2.20 [last]');
expect(getVersions(chromeLine)[1]).toContain('2.24');

expect(geckodriverLine).not.toBeNull();
expect(geckodriverLine).toContain('[default]');
expect(geckodriverLine).toContain('[last]');
expect(getVersions(geckodriverLine).length).toEqual(1);

expect(androidSdkLine).not.toBeNull();
expect(androidSdkLine).toContain('not present');
expect(appiumLine).not.toBeNull();
expect(appiumLine).toContain('not present');
});
});

0 comments on commit 72e3d9f

Please sign in to comment.