From 8ae205eb8de64da4617129738995a5a83fb8667d Mon Sep 17 00:00:00 2001 From: rofrischmann Date: Wed, 14 Sep 2016 21:34:48 +0200 Subject: [PATCH] #97 fixed windows phone fallback --- generator/generateData.js | 9 ++++----- modules/utils/getBrowserInformation.js | 17 +++++++++-------- package.json | 1 - test/prefixer-test.js | 12 +++++++----- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/generator/generateData.js b/generator/generateData.js index d9098d6..1e61fca 100644 --- a/generator/generateData.js +++ b/generator/generateData.js @@ -59,7 +59,7 @@ const browsers = [ 'chrome', 'safari', 'firefox', 'opera', 'ie', 'edge', 'ios_sa function gatherInformation() { const prefixProperties = { } - browsers.forEach(function (browser) { + browsers.forEach(function(browser) { prefixProperties[browser] = { } }) @@ -69,7 +69,7 @@ function gatherInformation() { if (properties instanceof Array !== true) { properties = [ properties ] } - properties.forEach(function (prop) { + properties.forEach(function(prop) { for (const prefix in prefixProperties) { if (versions[prefix].x >= config[prefix]) { prefixProperties[prefix][prop] = versions[prefix].x @@ -78,16 +78,15 @@ function gatherInformation() { }) } - prefixProperties.ie = assign({ }, prefixProperties.ie, prefixProperties.ie_mob) delete prefixProperties.ie_mob - flexPropsIE.forEach(function (prop) { + flexPropsIE.forEach(function(prop) { delete prefixProperties.ie[prop] }) return 'export default ' + JSON.stringify(prefixProperties) } -fs.writeFile('./modules/prefixProps.js', gatherInformation(), function (err) { +fs.writeFile('./modules/prefixProps.js', gatherInformation(), function(err) { if (err) { throw err } diff --git a/modules/utils/getBrowserInformation.js b/modules/utils/getBrowserInformation.js index bf8ec04..98aec6a 100644 --- a/modules/utils/getBrowserInformation.js +++ b/modules/utils/getBrowserInformation.js @@ -8,21 +8,21 @@ const browsers = { chrome: [ [ 'chrome' ], [ 'chromium' ] ], safari: [ [ 'safari' ] ], firefox: [ [ 'firefox' ] ], - ie: [ [ 'msie' ] ], edge: [ [ 'msedge' ] ], opera: [ [ 'opera' ], [ 'vivaldi' ] ], ios_saf: [ [ 'ios', 'mobile' ], [ 'ios', 'tablet' ] ], - ie_mob: [ [ 'windowsphone', 'mobile', 'msie' ], [ 'windowsphone', 'tablet', 'msie' ], [ 'windowsphone', 'mobile', 'msedge' ], [ 'windowsphone', 'tablet', 'msedge' ] ], + ie: [ [ 'msie' ] ], op_mini: [ [ 'opera', 'mobile' ], [ 'opera', 'tablet' ] ], and_uc: [ [ 'android', 'mobile' ], [ 'android', 'tablet' ] ], android: [ [ 'android', 'mobile' ], [ 'android', 'tablet' ] ] } -const browserByInfo = (info) => { - if (info['firefox']) { - return 'firefox'; +const browserByInfo = info => { + if (info.firefox) { + return 'firefox' } - let name = ''; + let name = '' + Object.keys(browsers).forEach(browser => { browsers[browser].forEach(condition => { let match = 0 @@ -32,11 +32,12 @@ const browserByInfo = (info) => { } }) if (condition.length === match) { - name = browser; + name = browser } }) }) - return name; + + return name } /** diff --git a/package.json b/package.json index 82b754a..1d678a5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "babel": "babel modules/ --out-dir lib", "build": "npm run clean && mkdir dist && npm run babel && npm run generate && npm run dist", "clean": "rimraf lib dist coverage", - "coverage": "codeclimate-test-reporter < coverage/lcov.info", "dist": "cross-env NODE_ENV=production babel-node buildPackage && cross-env NODE_ENV=development babel-node buildPackage", "generate": "babel-node generator/generateData.js", "pretest": "npm run clean && npm run babel && npm run generate", diff --git a/test/prefixer-test.js b/test/prefixer-test.js index df7f58d..1ab4ade 100644 --- a/test/prefixer-test.js +++ b/test/prefixer-test.js @@ -15,6 +15,7 @@ const Chrome49 = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, const SeaMonkey = 'Mozilla/5.0 (Windows NT 5.2; RW; rv:7.0a1) Gecko/20091211 SeaMonkey/9.23a1pre' const Chromium = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/50.0.2661.102 Chrome/50.0.2661.102 Safari/537.36' const PhantomJS = 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1' + describe('Prefixing a property', () => { it('should only add required prefixes', () => { const input = { appearance: 'test', transition: 'test' } @@ -45,6 +46,7 @@ describe('Prefixing a property', () => { describe('Prefixing 2D transforms', () => { const input = { transform: 'rotate(30deg)' } const prefixed = { msTransform: 'rotate(30deg)' } + it('should be prefixed on IE 9', () => { expect(new Prefixer({ userAgent: MSIE9 }).prefix(input)).to.eql(prefixed) }) @@ -69,11 +71,11 @@ describe('Running on android < 4.4', () => { expect(andPrefixer._browserInfo.version).to.eql(47) }) it('Should use firefox version on android 4.2.2', () => { - const andPrefixer = new Prefixer({ - userAgent: Android4_2_2Firefox48 - }) - expect(andPrefixer._browserInfo.osversion).to.eql(4.2) - expect(andPrefixer._browserInfo.version).to.eql(48) + const andPrefixer = new Prefixer({ + userAgent: Android4_2_2Firefox48 + }) + expect(andPrefixer._browserInfo.osversion).to.eql(4.2) + expect(andPrefixer._browserInfo.version).to.eql(48) }) }) describe('Running on iOS', () => {