From f63bc3cfdeef64e5cd995317271fd28bd1da06c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski?= Date: Thu, 25 May 2017 16:14:31 +0200 Subject: [PATCH] test(support): verify support tests results in all tested browsers (#16008) Closes #16008 --- test/auto/injectorSpec.js | 10 ++-- test/helpers/support.js | 20 +++++++ test/helpers/supportSpec.js | 97 ++++++++++++++++++++++++++++++++ test/helpers/testabilityPatch.js | 20 ------- 4 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 test/helpers/support.js create mode 100644 test/helpers/supportSpec.js diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index bf8fe284e7ed..2e272b356a1e 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -283,16 +283,16 @@ describe('injector', function() { describe('es6', function() { - if (support.ES6Function) { + if (support.shorthandMethods) { // The functions are generated using `eval` as just having the ES6 syntax can break some browsers. - it('should be possible to annotate functions that are declared using ES6 syntax', function() { + it('should be possible to annotate shorthand methods', function() { // eslint-disable-next-line no-eval expect(annotate(eval('({ fn(x) { return; } })').fn)).toEqual(['x']); }); } - if (support.fatArrow) { + if (support.fatArrows) { it('should create $inject for arrow functions', function() { // eslint-disable-next-line no-eval expect(annotate(eval('(a, b) => a'))).toEqual(['a', 'b']); @@ -300,7 +300,7 @@ describe('injector', function() { } - if (support.fatArrow) { + if (support.fatArrows) { it('should create $inject for arrow functions with no parenthesis', function() { // eslint-disable-next-line no-eval expect(annotate(eval('a => a'))).toEqual(['a']); @@ -308,7 +308,7 @@ describe('injector', function() { } - if (support.fatArrow) { + if (support.fatArrows) { it('should take args before first arrow', function() { // eslint-disable-next-line no-eval expect(annotate(eval('a => b => b'))).toEqual(['a']); diff --git a/test/helpers/support.js b/test/helpers/support.js new file mode 100644 index 000000000000..af84dbbecb49 --- /dev/null +++ b/test/helpers/support.js @@ -0,0 +1,20 @@ +'use strict'; + +var supportTests = { + classes: '/^class\\b/.test((class C {}).toString())', + fatArrows: 'a => a', + shorthandMethods: '({ fn(x) { return; } })' +}; + +var support = {}; + +for (var prop in supportTests) { + if (supportTests.hasOwnProperty(prop)) { + try { + // eslint-disable-next-line no-eval + support[prop] = !!eval(supportTests[prop]); + } catch (e) { + support[prop] = false; + } + } +} diff --git a/test/helpers/supportSpec.js b/test/helpers/supportSpec.js new file mode 100644 index 000000000000..e46112d08ef7 --- /dev/null +++ b/test/helpers/supportSpec.js @@ -0,0 +1,97 @@ +'use strict'; + +describe('support test results', function() { + var expected, version, testName; + var userAgent = window.navigator.userAgent; + + // Support: iOS 8 only + if (/iPhone OS 10_1\d(?:_\d+)? /.test(userAgent)) { + // iOS 8 official simulators have broken user agent (containing something like `iPhone OS 10_12_5`, + // i.e. the macOS version in place of the iOS version) so they'd fall into an incorrect bucket. + // Fix the user agent there. + // NOTE: Make sure the above check doesn't catch the real iOS 10! + userAgent = userAgent.replace(/iPhone OS 10(?:_\d+)+/, 'iPhone OS 8_1'); + } + + if (/edge\//i.test(userAgent)) { + expected = { + classes: true, + fatArrows: true, + shorthandMethods: true + }; + } else if (/msie|trident/i.test(userAgent)) { + expected = { + classes: false, + fatArrows: false, + shorthandMethods: false + }; + } else if (/iphone os [78]_/i.test(userAgent)) { + expected = { + classes: false, + fatArrows: false, + shorthandMethods: false + }; + } else if (/iphone os 9_/i.test(userAgent)) { + expected = { + classes: true, + fatArrows: false, + shorthandMethods: true + }; + } else if (/iphone os/i.test(userAgent)) { + expected = { + classes: true, + fatArrows: true, + shorthandMethods: true + }; + } else if (/android 4\.[0-3]/i.test(userAgent)) { + expected = { + classes: false, + fatArrows: false, + shorthandMethods: false + }; + } else if (/chrome/i.test(userAgent)) { + // Catches Chrome on Android as well (i.e. the default + // Android browser on Android >= 4.4). + expected = { + classes: true, + fatArrows: true, + shorthandMethods: true + }; + } else if (/firefox/i.test(userAgent)) { + version = parseInt(userAgent.match(/firefox\/(\d+)/i)[1], 10); + expected = { + classes: version >= 55, + fatArrows: true, + shorthandMethods: true + }; + } else if (/\b8(?:\.\d+)+ safari/i.test(userAgent)) { + expected = { + classes: false, + fatArrows: false, + shorthandMethods: false + }; + } else if (/\b9(?:\.\d+)+ safari/i.test(userAgent)) { + expected = { + classes: true, + fatArrows: false, + shorthandMethods: true + }; + } else if (/\b\d+(?:\.\d+)+ safari/i.test(userAgent)) { + expected = { + classes: true, + fatArrows: true, + shorthandMethods: true + }; + } + + it('should have expected values specified', function() { + expect(expected).not.toBe(null); + expect(typeof expected).toBe('object'); + }); + + for (testName in expected) { + it('should report support.' + testName + ' to be ' + expected[testName], function() { + expect(support[testName]).toBe(expected[testName]); + }); + } +}); diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js index e212581a2950..c397af35e6e6 100644 --- a/test/helpers/testabilityPatch.js +++ b/test/helpers/testabilityPatch.js @@ -3,26 +3,6 @@ if (window.bindJQuery) bindJQuery(); -var supportTests = { - classes: '/^class\\b/.test((class C {}).toString())', - fatArrow: 'a => a', - ES6Function: '({ fn(x) { return; } })' -}; - -var support = {}; - -for (var prop in supportTests) { - if (supportTests.hasOwnProperty(prop)) { - try { - // eslint-disable-next-line no-eval - support[prop] = !!eval(supportTests[prop]); - } catch (e) { - support[prop] = false; - } - } -} - - beforeEach(function() { // all this stuff is not needed for module tests, where jqlite and publishExternalAPI and jqLite are not global vars