diff --git a/lib/flatten_browser.js b/lib/flatten_browser.js index ebe7fee..4d8e039 100644 --- a/lib/flatten_browser.js +++ b/lib/flatten_browser.js @@ -118,10 +118,6 @@ 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; } @@ -129,6 +125,13 @@ function flatten(request, all_browsers) { 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); } diff --git a/test/unit/flatten-browser.js b/test/unit/flatten-browser.js index f071ca7..20d2393 100644 --- a/test/unit/flatten-browser.js +++ b/test/unit/flatten-browser.js @@ -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(); +});