2017-04-09 14:13:00 +00:00
|
|
|
import test from 'ava';
|
2018-06-30 16:40:10 +00:00
|
|
|
import {
|
|
|
|
getFirstMatch,
|
|
|
|
getWindowsVersionName,
|
2018-07-02 20:30:48 +00:00
|
|
|
compareVersions,
|
2018-06-30 16:40:10 +00:00
|
|
|
} from '../../src/utils';
|
2017-04-09 14:13:00 +00:00
|
|
|
|
2018-06-27 20:09:45 +00:00
|
|
|
test('getFirstMatch', (t) => {
|
2017-04-09 14:13:00 +00:00
|
|
|
const matchedVersion = getFirstMatch(/version\/(\S+)/i, 'Chrome Version/11.11.11');
|
|
|
|
t.is(matchedVersion, '11.11.11');
|
|
|
|
});
|
2018-06-30 16:40:10 +00:00
|
|
|
|
|
|
|
test('getWindowsVersionName', (t) => {
|
|
|
|
t.is(getWindowsVersionName('NT 5.0'), '2000');
|
|
|
|
t.is(getWindowsVersionName('XXX'), void 0);
|
|
|
|
});
|
2018-07-02 20:30:48 +00:00
|
|
|
|
|
|
|
test('compareVersions', (t) => {
|
|
|
|
const comparisionsTasks = [
|
|
|
|
['9.0', '10', -1],
|
|
|
|
['11', '10', 1],
|
|
|
|
['1.10.2.1', '1.8.2.1.90', 1],
|
|
|
|
['1.010.2.1', '1.08.2.1.90', 1],
|
|
|
|
['1.10.2.1', '1.10.2.1', 0],
|
|
|
|
['1.10.2.1', '1.0800.2', -1],
|
|
|
|
['1.0.0-alpha', '1.0.0-alpha.1', -1],
|
|
|
|
['1.0.0-alpha.1', '1.0.0-alpha.beta', -1],
|
|
|
|
['1.0.0-alpha.beta', '1.0.0-beta', -1],
|
|
|
|
['1.0.0-beta', '1.0.0-beta.2', -1],
|
|
|
|
['1.0.0-beta.11', '1.0.0-rc.1', -1],
|
|
|
|
['1.0.0-rc.1', '1.0.0', -1],
|
|
|
|
];
|
|
|
|
|
|
|
|
comparisionsTasks.forEach((testingParams) => {
|
|
|
|
const versionA = testingParams[0];
|
|
|
|
const versionB = testingParams[1];
|
|
|
|
const result = testingParams[2];
|
|
|
|
let matching = ' == ';
|
|
|
|
|
|
|
|
if (result > 0) {
|
|
|
|
matching = ' > ';
|
|
|
|
} else if (result < 0) {
|
|
|
|
matching = ' < ';
|
|
|
|
}
|
|
|
|
|
|
|
|
t.is(compareVersions(versionA, versionB), result, `version ${versionA} should be ${matching} version ${versionB}`);
|
|
|
|
});
|
|
|
|
});
|