From 9a2f2bef1d0c6af1c83e87db11248959b648e1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Fri, 22 Jul 2016 11:33:14 +0200 Subject: [PATCH 1/2] Fix existing tests --- test/index.js | 5 +++-- test/utils.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/index.js b/test/index.js index 9673df0..a4a4ecb 100644 --- a/test/index.js +++ b/test/index.js @@ -41,7 +41,7 @@ test("getSupport tests", (t) => { let borderRadiusSupport = { safari: { y: 3.1, x: 4, '#1': 6.1 }, opera: { n: 10, y: 10.5 }, - op_mini: { n: 5 }, + op_mini: {}, ios_saf: { y: 3.2, x: 3.2 }, ie_mob: { y: 10 }, edge: { y: 12 }, @@ -51,7 +51,8 @@ test("getSupport tests", (t) => { android: { y: 2.1, x: 2.1 }, and_uc: { y: 9.9 }, // workaround for https://github.com/Nyalab/caniuse-api/issues/19 - and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) } + and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) }, + samsung: { y: 4 } } t.deepEqual(caniuse.getSupport("border-radius"), borderRadiusSupport, "border-radius support is ok") diff --git a/test/utils.js b/test/utils.js index 1ce9d98..6002cfa 100644 --- a/test/utils.js +++ b/test/utils.js @@ -17,7 +17,7 @@ test("parseCaniuseData should work", (t) => { let correctSupport = { safari: { y: 3.1, x: 4, '#1': 6.1 }, opera: { n: 10, y: 10.5 }, - op_mini: { n: 5 }, + op_mini: { }, ios_saf: { y: 3.2, x: 3.2 }, ie_mob: { y: 10 }, ie: { n: 8, y: 9 }, @@ -27,7 +27,8 @@ test("parseCaniuseData should work", (t) => { android: { y: 2.1, x: 2.1 }, and_uc: { y: 9.9 }, // workaround for https://github.com/Nyalab/caniuse-api/issues/19 - and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) } + and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) }, + samsung: { y: 4 } } t.deepEqual(parseCaniuseData(borderRadiusFeature, browsers), correctSupport, "border-radius support is correct") From 647ba7e77ad529a994db4cfde6a5a248bc74e97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Goetz?= Date: Fri, 22 Jul 2016 11:34:57 +0200 Subject: [PATCH 2/2] Do not fail if browserslist returns a browser that caniuse-api doesn't know about --- src/index.js | 2 +- test/index.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 57d21bf..f5a511e 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,7 @@ function isSupported(feature, browsers) { return browserslist(browsers) .map((browser) => browser.split(" ")) - .every((browser) => data.stats[browser[0]][browser[1]] === "y") + .every((browser) => data.stats[browser[0]] && data.stats[browser[0]][browser[1]] === "y") } function find(query) { diff --git a/test/index.js b/test/index.js index a4a4ecb..1b52897 100644 --- a/test/index.js +++ b/test/index.js @@ -34,6 +34,23 @@ test("isSupported tests", (t) => { t.end() }) +// If for some reason the caniuse-db is not the same in browserslist and in caniuse-api +// browserslist could return browsers that caniuse-api doesn't know about and crashes +test("isSupported test with browsers caniuse doesn't know", (t) => { + browserslist.data.notabrowser = { + name: 'notabrowser', + versions: ['1'], + released: ['1'] + }; + browserslist.versionAliases.notabrowser = {} + + t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data") + + delete browserslist.data.notabrowser + delete browserslist.versionAliases.notabrowser + t.end() +}) + test("getSupport tests", (t) => { caniuse.setBrowserScope()