Skip to content

Commit 067f4a1

Browse files
authored
Merge pull request #952 from wahidrizka/fix-cover-null-usage
Do not add versions without usage data to cover queries
2 parents 5be63f5 + f760921 commit 067f4a1

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)