未验证 提交 fde38d5c 编写于 作者: M Mislav Marohnić 提交者: GitHub

Merge pull request #652 from github/karma-update

Update Karma and detect available browsers when testing
...@@ -3,7 +3,7 @@ const parentConfig = require('./karma.config') ...@@ -3,7 +3,7 @@ const parentConfig = require('./karma.config')
module.exports = function(config) { module.exports = function(config) {
parentConfig(config) parentConfig(config)
config.set({ config.set({
frameworks: ['mocha'], frameworks: ['detectBrowsers', 'mocha'],
files: [ files: [
'test/worker-adapter.js', 'test/worker-adapter.js',
{ {
......
...@@ -3,7 +3,18 @@ const serverEndpoints = require('./server') ...@@ -3,7 +3,18 @@ const serverEndpoints = require('./server')
module.exports = function(config) { module.exports = function(config) {
config.set({ config.set({
basePath: '..', basePath: '..',
frameworks: ['mocha', 'chai'], frameworks: ['detectBrowsers', 'mocha', 'chai'],
detectBrowsers: {
preferHeadless: true,
usePhantomJS: false,
postDetection: availableBrowsers =>
availableBrowsers
.filter(
browser =>
!process.env.CI || !browser.startsWith('Chromium') || !availableBrowsers.some(b => b.startsWith('Chrome'))
)
.map(browser => (browser.startsWith('Chrom') ? `${browser}NoSandbox` : browser))
},
client: { client: {
mocha: { mocha: {
ui: 'tdd' ui: 'tdd'
...@@ -20,7 +31,6 @@ module.exports = function(config) { ...@@ -20,7 +31,6 @@ module.exports = function(config) {
port: 9876, port: 9876,
colors: true, colors: true,
logLevel: process.env.CI ? config.LOG_WARN : config.LOG_INFO, logLevel: process.env.CI ? config.LOG_WARN : config.LOG_INFO,
browsers: ['ChromeHeadlessNoSandbox', 'FirefoxHeadless'],
autoWatch: false, autoWatch: false,
singleRun: true, singleRun: true,
concurrency: Infinity, concurrency: Infinity,
...@@ -29,10 +39,9 @@ module.exports = function(config) { ...@@ -29,10 +39,9 @@ module.exports = function(config) {
base: 'ChromeHeadless', base: 'ChromeHeadless',
flags: ['--no-sandbox'] flags: ['--no-sandbox']
}, },
FirefoxHeadless: { ChromiumHeadlessNoSandbox: {
base: 'Firefox', base: 'ChromiumHeadless',
flags: ['-headless'], flags: ['--no-sandbox']
displayName: 'HeadlessFirefox'
} }
}, },
beforeMiddleware: ['custom'], beforeMiddleware: ['custom'],
......
var IEorEdge = /Edge\//.test(navigator.userAgent) || /MSIE/.test(navigator.userAgent) var IEorEdge = /Edge\//.test(navigator.userAgent) || /MSIE/.test(navigator.userAgent)
var Chrome = /Chrome\//.test(navigator.userAgent) && !IEorEdge
var Safari = /Safari\//.test(navigator.userAgent) && !IEorEdge && !Chrome
var support = { var support = {
url: (function(url) { url: (function(url) {
...@@ -116,12 +118,14 @@ exercise.forEach(function(exerciseMode) { ...@@ -116,12 +118,14 @@ exercise.forEach(function(exerciseMode) {
}) })
} }
var nativeChrome = /Chrome\//.test(navigator.userAgent) && !IEorEdge && exerciseMode === 'native' var nativeChrome = Chrome && exerciseMode === 'native'
var nativeSafari = /Safari\//.test(navigator.userAgent) && !IEorEdge && exerciseMode === 'native' var nativeSafari = Safari && exerciseMode === 'native'
var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native' var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native'
var firefox = navigator.userAgent.match(/Firefox\/(\d+)/) var firefox = navigator.userAgent.match(/Firefox\/(\d+)/)
var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native' var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native'
var polyfillFirefox = firefox && exerciseMode === 'polyfill' var polyfillFirefox = firefox && exerciseMode === 'polyfill'
var omitSafari =
Safari && exerciseMode === 'native' && navigator.userAgent.match(/Version\/(\d+\.\d+)/)[1] <= '11.1'
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
function testBodyExtract(factory) { function testBodyExtract(factory) {
...@@ -541,7 +545,7 @@ exercise.forEach(function(exerciseMode) { ...@@ -541,7 +545,7 @@ exercise.forEach(function(exerciseMode) {
return new Request('', {method: 'POST', body: body}) return new Request('', {method: 'POST', body: body})
}) })
test('credentials defaults to same-origin', function() { featureDependent(test, !omitSafari, 'credentials defaults to same-origin', function() {
var request = new Request('') var request = new Request('')
assert.equal(request.credentials, 'same-origin') assert.equal(request.credentials, 'same-origin')
}) })
...@@ -1104,13 +1108,10 @@ exercise.forEach(function(exerciseMode) { ...@@ -1104,13 +1108,10 @@ exercise.forEach(function(exerciseMode) {
controller.abort() controller.abort()
}, 30) }, 30)
var start = new Date()
return fetch('/slow?_=' + new Date().getTime(), { return fetch('/slow?_=' + new Date().getTime(), {
signal: controller.signal signal: controller.signal
}).then( }).then(
function() { function() {
assert.isAtLeast(new Date() - start, 100, 'request finished too soon')
assert.ok(false) assert.ok(false)
}, },
function(error) { function(error) {
...@@ -1127,11 +1128,8 @@ exercise.forEach(function(exerciseMode) { ...@@ -1127,11 +1128,8 @@ exercise.forEach(function(exerciseMode) {
controller.abort() controller.abort()
}, 30) }, 30)
var start = new Date()
return fetch(request).then( return fetch(request).then(
function() { function() {
assert.isAtLeast(new Date() - start, 100, 'request finished too soon')
assert.ok(false) assert.ok(false)
}, },
function(error) { function(error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册