Skip to content

Commit f760921

Browse files
committed
Do not add versions without usage data to cover queries
caniuse-lite region data has null usage for versions it has no data for, including unreleased ones. coverQuery stopped only at a usage of 0, so a region whose data adds up to less than the requested coverage got every null version that comes before the first 0 in the data, the ones of Firefox, Chrome, Opera, Edge and Safari: `cover 99.5% in US` returned 629 versions, 372 of them with null usage.
1 parent 5b7e941 commit f760921

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,9 @@ function coverQuery(context, node) {
675675
var version
676676
for (var i = 0; i < versions.length; i++) {
677677
version = versions[i]
678-
if (usage[version] === 0) break
678+
// Region data has `null` for versions without usage data. Like zero usage,
679+
// they add nothing to the coverage and sort together with the zeros.
680+
if (!usage[version]) break
679681
covered += usage[version]
680682
result.push(version)
681683
if (covered >= coverage) break

‎test/cover.test.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ test('does not add zero-popularity', () => {
7474
equal(browserslist('cover 20% in my stats', stats), ['ie 11'])
7575
})
7676

77+
test('does not add versions without usage data', () => {
78+
equal(browserslist('cover 30% in my stats'), [
79+
'chrome 37',
80+
'chrome 36',
81+
'chrome 35',
82+
'chrome 34',
83+
'ie 11',
84+
'ie 10',
85+
'ie 9',
86+
'ie 8'
87+
])
88+
})
89+
90+
test('does not add versions without usage data in a country', () => {
91+
browserslist.usage.US['ie 10'] = null
92+
browserslist.usage.US['ie 11'] = 0
93+
equal(browserslist('cover 10% in US'), ['ie 9', 'ie 8'])
94+
})
95+
7796
test('throws error on no stats', () => {
7897
delete process.env.BROWSERSLIST_STATS
7998
throws(

0 commit comments

Comments
 (0)