diff --git a/lib/helper.js b/lib/helper.js index b3d64b24f..a4ea9613d 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -3,14 +3,16 @@ const fs = require('graceful-fs') const path = require('path') const _ = require('lodash') -const useragent = require('useragent') +const useragent = require('ua-parser-js') const Promise = require('bluebird') const mm = require('minimatch') exports.browserFullNameToShort = (fullName) => { - const agent = useragent.parse(fullName) - const isUnknown = agent.family === 'Other' || agent.os.family === 'Other' - return isUnknown ? fullName : `${agent.toAgent()} (${agent.os})` + const au = useragent(fullName) + if (!au.browser.name && !au.browser.version && !au.os.name && !au.os.version) { + return fullName + } + return `${au.browser.name} ${au.browser.version || '0.0.0'} (${au.os.name} ${au.os.version || '0.0.0'})` } exports.isDefined = (value) => { diff --git a/package-lock.json b/package-lock.json index 1d3089f57..cf77e75bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6327,22 +6327,6 @@ "integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw=", "dev": true }, - "lru-cache": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - }, - "dependencies": { - "yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" - } - } - }, "make-iterator": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/make-iterator/-/make-iterator-1.0.1.tgz", @@ -7672,11 +7656,6 @@ "event-stream": "=3.3.4" } }, - "pseudomap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" - }, "public-encrypt": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", @@ -9201,6 +9180,11 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "ua-parser-js": { + "version": "0.7.21", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.21.tgz", + "integrity": "sha512-+O8/qh/Qj8CgC6eYBVBykMrNtp5Gebn4dlGD/kKXVkJNDwyrAwSIqwz8CDf+tsAIWVycKcku6gIXJ0qwx/ZXaQ==" + }, "uglify-js": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", @@ -9382,15 +9366,6 @@ "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "dev": true }, - "useragent": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/useragent/-/useragent-2.3.0.tgz", - "integrity": "sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw==", - "requires": { - "lru-cache": "4.1.x", - "tmp": "0.0.x" - } - }, "util": { "version": "0.10.4", "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", diff --git a/package.json b/package.json index f0fa1d647..962e76d9f 100644 --- a/package.json +++ b/package.json @@ -415,7 +415,7 @@ "socket.io": "2.1.1", "source-map": "^0.6.1", "tmp": "0.0.33", - "useragent": "2.3.0" + "ua-parser-js": "0.7.21" }, "devDependencies": { "browserify": "^16.2.3", diff --git a/test/e2e/basic.feature b/test/e2e/basic.feature index 8f496d44d..8246e21e6 100644 --- a/test/e2e/basic.feature +++ b/test/e2e/basic.feature @@ -17,7 +17,7 @@ Feature: Basic Testrunner Then it passes with: """ .. - HeadlessChrome + Chrome Headless """ @not-jenkins Scenario: Execute a test in Chrome diff --git a/test/e2e/browser_console.feature b/test/e2e/browser_console.feature index 69b3085a1..409313b31 100644 --- a/test/e2e/browser_console.feature +++ b/test/e2e/browser_console.feature @@ -128,7 +128,7 @@ Feature: Browser Console Configuration When I start Karma Then the file at test/e2e/console.log contains: """ - HeadlessChrome + Chrome Headless """ Scenario: Execute logging program and disabling terminal @@ -150,7 +150,7 @@ Feature: Browser Console Configuration Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: Execute logging program and disabling terminal @@ -170,7 +170,7 @@ Feature: Browser Console Configuration Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: Execute logging program with singleRun Given a configuration with: diff --git a/test/e2e/custom-context.feature b/test/e2e/custom-context.feature index ed4e03fde..40bc19e9f 100644 --- a/test/e2e/custom-context.feature +++ b/test/e2e/custom-context.feature @@ -18,5 +18,5 @@ Feature: Custom Context File Then it passes with: """ . - HeadlessChrome + Chrome Headless """ diff --git a/test/e2e/files.feature b/test/e2e/files.feature index bee5b9922..4074f5280 100644 --- a/test/e2e/files.feature +++ b/test/e2e/files.feature @@ -20,7 +20,7 @@ Feature: Including files Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: Execute a test excluding an explicitly included file @@ -41,7 +41,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ @@ -66,7 +66,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ @@ -91,7 +91,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ @@ -116,7 +116,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ @@ -141,7 +141,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ @@ -167,7 +167,7 @@ Feature: Including files Then it passes with like: """ . - HeadlessChrome + Chrome Headless """ And it passes with like: """ diff --git a/test/e2e/headers.feature b/test/e2e/headers.feature index a90ce692d..9f19256cb 100644 --- a/test/e2e/headers.feature +++ b/test/e2e/headers.feature @@ -22,5 +22,5 @@ Feature: Custom Headers Then it passes with: """ . - HeadlessChrome + Chrome Headless """ diff --git a/test/e2e/middleware.feature b/test/e2e/middleware.feature index d9bc54a9b..9127ff339 100644 --- a/test/e2e/middleware.feature +++ b/test/e2e/middleware.feature @@ -21,7 +21,7 @@ Feature: Middleware Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: Frameworks can add middleware @@ -40,5 +40,5 @@ Feature: Middleware Then it passes with: """ . - HeadlessChrome + Chrome Headless """ diff --git a/test/e2e/proxy.feature b/test/e2e/proxy.feature index d5db29a4b..8398c36f7 100644 --- a/test/e2e/proxy.feature +++ b/test/e2e/proxy.feature @@ -20,7 +20,7 @@ Feature: Proxying Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: Added by a framework @@ -39,7 +39,7 @@ Feature: Proxying Then it passes with: """ . - HeadlessChrome + Chrome Headless """ Scenario: URLRoot @@ -60,5 +60,5 @@ Feature: Proxying Then it passes with: """ . - HeadlessChrome + Chrome Headless """ diff --git a/test/e2e/reconnecting.feature b/test/e2e/reconnecting.feature index cd6def4e5..829cbaec7 100644 --- a/test/e2e/reconnecting.feature +++ b/test/e2e/reconnecting.feature @@ -22,5 +22,5 @@ Feature: Passing Options Then it passes with: """ ..... - HeadlessChrome + Chrome Headless """ diff --git a/test/e2e/runInParent.feature b/test/e2e/runInParent.feature index 52efb3ef3..149a796c6 100644 --- a/test/e2e/runInParent.feature +++ b/test/e2e/runInParent.feature @@ -21,7 +21,7 @@ Feature: runInParent option Then it passes with: """ .. - HeadlessChrome + Chrome Headless """ @not-jenkins Scenario: Execute a test in Chrome diff --git a/test/e2e/upstream-proxy.feature b/test/e2e/upstream-proxy.feature index 9b19c5709..7d6b53aad 100644 --- a/test/e2e/upstream-proxy.feature +++ b/test/e2e/upstream-proxy.feature @@ -7,7 +7,7 @@ Feature: UpstreamProxy Given a configuration with: """ files = ['behind-proxy/plus.js', 'behind-proxy/test.js']; - browsers = ['ChromeHeadlessNoSandbox']; + browsers = ['ChromeHeadless']; plugins = [ 'karma-jasmine', 'karma-chrome-launcher' @@ -20,5 +20,5 @@ Feature: UpstreamProxy When I start Karma behind a proxy on port 9875 that prepends '/__proxy__/' to the base path Then it passes with regexp: """ - HeadlessChrome.*Executed.*SUCCESS + Chrome Headless.*Executed.*SUCCESS """ diff --git a/test/unit/browser.spec.js b/test/unit/browser.spec.js index 3c1113c09..ec889b083 100644 --- a/test/unit/browser.spec.js +++ b/test/unit/browser.spec.js @@ -28,7 +28,7 @@ describe('Browser', () => { it('should set fullName and name', () => { const fullName = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7' browser = new Browser('id', fullName, collection, emitter, socket) - expect(browser.name).to.equal('Chrome 16.0.912 (Mac OS X 10.6.8)') + expect(browser.name).to.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)') expect(browser.fullName).to.equal(fullName) }) @@ -66,7 +66,7 @@ describe('Browser', () => { it('should return browser name', () => { const fullName = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7' browser = new Browser('id', fullName, collection, emitter, socket) - expect(browser.toString()).to.equal('Chrome 16.0.912 (Mac OS X 10.6.8)') + expect(browser.toString()).to.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)') }) it('should return verbatim user agent string for unrecognized browser', () => { diff --git a/test/unit/helper.spec.js b/test/unit/helper.spec.js index 43a08b043..8c5808c50 100644 --- a/test/unit/helper.spec.js +++ b/test/unit/helper.spec.js @@ -14,7 +14,7 @@ describe('helper', () => { 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 ' + '(KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25' ) - .to.be.equal('Mobile Safari 6.0.0 (iOS 6.0.0)') + .to.be.equal('Mobile Safari 6.0 (iOS 6.0)') }) it('should parse Linux', () => { @@ -22,14 +22,14 @@ describe('helper', () => { 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.19) Gecko/20081216 ' + 'Ubuntu/8.04 (hardy) Firefox/2.0.0.19' ) - .to.be.equal('Firefox 2.0.0 (Ubuntu 8.04.0)') + .to.be.equal('Firefox 2.0.0.19 (Ubuntu 8.04)') }) it('should degrade gracefully when OS not recognized', () => { expecting( 'Mozilla/5.0 (X11; U; FreeBSD; i386; en-US; rv:1.7) Gecko/20081216 ' + 'Firefox/2.0.0.19' - ).to.be.equal('Firefox 2.0.0 (FreeBSD 0.0.0)') + ).to.be.equal('Firefox 2.0.0.19 (FreeBSD 0.0.0)') }) it('should parse Chrome', () => { @@ -37,13 +37,13 @@ describe('helper', () => { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7' ) - .to.be.equal('Chrome 16.0.912 (Mac OS X 10.6.8)') + .to.be.equal('Chrome 16.0.912.63 (Mac OS 10.6.8)') expecting( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.15 ' + '(KHTML, like Gecko) Chrome/18.0.985.0 Safari/535.15' ) - .to.be.equal('Chrome 18.0.985 (Mac OS X 10.6.8)') + .to.be.equal('Chrome 18.0.985.0 (Mac OS 10.6.8)') }) it('should parse Firefox', () => { @@ -51,7 +51,7 @@ describe('helper', () => { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 ' + 'Firefox/7.0.1' ) - .to.be.equal('Firefox 7.0.1 (Mac OS X 10.6.0)') + .to.be.equal('Firefox 7.0.1 (Mac OS 10.6)') }) it('should parse Opera', () => { @@ -59,7 +59,7 @@ describe('helper', () => { 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 ' + 'Version/11.52' ) - .to.be.equal('Opera 11.52.0 (Mac OS X 10.6.8)') + .to.be.equal('Opera 11.52 (Mac OS 10.6.8)') }) it('should parse Safari', () => { @@ -67,7 +67,7 @@ describe('helper', () => { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.52.7 ' + '(KHTML, like Gecko) Version/5.1.2 Safari/534.52.7' ) - .to.be.equal('Safari 5.1.2 (Mac OS X 10.6.8)') + .to.be.equal('Safari 5.1.2 (Mac OS 10.6.8)') }) it('should parse IE7', () => { @@ -75,7 +75,7 @@ describe('helper', () => { 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; ' + '.NET CLR 2.0.50727; .NET4.0C; .NET4.0E)' ) - .to.be.equal('IE 7.0.0 (Windows Vista.0.0)') + .to.be.equal('IE 7.0 (Windows Vista)') }) it('should parse IE8', () => { @@ -83,7 +83,7 @@ describe('helper', () => { 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; ' + 'SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)"' ) - .to.be.equal('IE 8.0.0 (Windows 7.0.0)') + .to.be.equal('IE 8.0 (Windows 7)') }) it('should parse IE9', () => { @@ -91,7 +91,7 @@ describe('helper', () => { 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; ' + '.NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)' ) - .to.be.equal('IE 9.0.0 (Windows 7.0.0)') + .to.be.equal('IE 9.0 (Windows 7)') }) it('should parse IE10', () => { @@ -99,7 +99,7 @@ describe('helper', () => { 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; ' + '.NET4.0E; .NET4.0C)' ) - .to.be.equal('IE 10.0.0 (Windows 8.0.0)') + .to.be.equal('IE 10.0 (Windows 8)') }) it('should parse PhantomJS', () => { @@ -107,7 +107,7 @@ describe('helper', () => { 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) ' + 'PhantomJS/1.6.0 Safari/534.34' ) - .to.be.equal('PhantomJS 1.6.0 (Mac OS X 0.0.0)') + .to.be.equal('PhantomJS 1.6.0 (Mac OS 0.0.0)') }) // Fix for #318 @@ -116,7 +116,7 @@ describe('helper', () => { 'Mozilla/5.0 (Linux; U; Android 4.2; en-us; sdk Build/JB_MR1) ' + 'AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' ) - .to.be.equal('Android 4.2.0 (Android 4.2.0)') + .to.be.equal('Android Browser 4.0 (Android 4.2)') }) it('should parse Headless Chrome', () => { @@ -124,7 +124,15 @@ describe('helper', () => { 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'HeadlessChrome/70.0.3538.77 Safari/537.36' ) - .to.be.equal('HeadlessChrome 70.0.3538 (Linux 0.0.0)') + .to.be.equal('Chrome Headless 70.0.3538.77 (Linux x86_64)') + }) + + it('should parse MS Edge Chromium', () => { + expecting( + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' + + 'Chrome/80.0.3987.132 Safari/537.36 Edg/80.0.361.66' + ) + .to.be.equal('Edge 80.0.361.66 (Windows 10)') }) })