Skip to content

Commit

Permalink
Merge pull request defunctzombie#231 from mcous/add-last-N-versions
Browse files Browse the repository at this point in the history
Allow negative number for start of browser range
  • Loading branch information
defunctzombie committed Aug 31, 2015
2 parents ecfdf46 + d022de6 commit 24b4a92
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/flatten_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,20 @@ function flatten(request, all_browsers) {
return item.version;
});

if (start !== 'oldest') {
start_idx = v_map.indexOf(start);
}

if (end === 'latest') {
end_idx = get_numeric_versions(avail).length - 1;
}
else {
end_idx = v_map.lastIndexOf(end);
}

if (start < 0) {
start_idx = end_idx + Number(start);
}
else if (start !== 'oldest') {
start_idx = v_map.indexOf(start);
}

if (start_idx < 0) {
throw new Error('unable to find start version: ' + start);
}
Expand Down
51 changes: 51 additions & 0 deletions test/unit/flatten-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,54 @@ test('flatten browser:stable', function(done) {

done();
});

test('flatten browser:negative', function(done) {
var request = [
{name: 'chrome', version: '-3..latest', platform: 'Windows 2012 R2'},
{name: 'safari', version: '-1..latest'},
{name: 'ipad', version: '-2..8.1', platform: 'Mac 10.10'}
];

var expected = [
{name: 'chrome', version: '39', platform: 'Windows 2012 R2'},
{name: 'chrome', version: '40', platform: 'Windows 2012 R2'},
{name: 'chrome', version: '41', platform: 'Windows 2012 R2'},
{name: 'chrome', version: '42', platform: 'Windows 2012 R2'},
{name: 'safari', version: '7', platform: 'Mac 10.9'},
{name: 'safari', version: '8', platform: 'Mac 10.10'},
{name: 'ipad', version: '7.1', platform: 'Mac 10.10'},
{name: 'ipad', version: '8.0', platform: 'Mac 10.10'},
{name: 'ipad', version: '8.1', platform: 'Mac 10.10'}
];

assert.deepEqual(
flattenBrowser(request, allBrowsers),
expected,
'We found the browsers to test'
);

done();
});

test('flatten browser:oldest', function(done) {
var request = [
{name: 'chrome', version: 'oldest', platform: 'Windows 2012 R2'},
{name: 'firefox', version: 'oldest..4', platform: 'Windows 2012 R2'}
];

var expected = [
{name: 'chrome', version: '26', platform: 'Windows 2012 R2'},
{name: 'firefox', version: '3.0', platform: 'Windows 2012 R2'},
{name: 'firefox', version: '3.5', platform: 'Windows 2012 R2'},
{name: 'firefox', version: '3.6', platform: 'Windows 2012 R2'},
{name: 'firefox', version: '4', platform: 'Windows 2012 R2'}
];

assert.deepEqual(
flattenBrowser(request, allBrowsers),
expected,
'We found the browsers to test'
);

done();
});

0 comments on commit 24b4a92

Please sign in to comment.