提交 4f097017 编写于 作者: M Mislav Marohnić

Convert testing fetch under Web Workers to Karma

上级 b5395890
......@@ -29,6 +29,6 @@
"scripts": {
"prepublish": "make dist/fetch.umd.js",
"pretest": "make",
"test": "karma start ./test/karma.config.js"
"test": "karma start ./test/karma.config.js && karma start ./test/karma-worker.config.js"
}
}
const parentConfig = require('./karma.config')
module.exports = function(config) {
parentConfig(config)
config.set({
frameworks: ['mocha'],
files: [
'test/worker-adapter.js',
{
pattern: '{test,dist}/*.js',
included: false
},
{
pattern: 'node_modules/{mocha,chai}/*.js',
included: false,
watched: false
}
]
})
}
......@@ -2,13 +2,14 @@ const serverEndpoints = require('./server')
module.exports = function(config) {
config.set({
basePath: '..',
frameworks: ['mocha', 'chai'],
client: {
mocha: {
ui: 'tdd'
}
},
files: ['../dist/fetch.umd.js', 'test.js'],
files: ['dist/fetch.umd.js', 'test/test.js'],
reporters: ['progress'],
port: 9876,
colors: true,
......
/* global Mocha */
var mochaRun = mocha.run
mocha.run = function() {}
mocha.suite.suites.unshift(Mocha.Suite.create(mocha.suite, 'worker'))
var worker = new Worker('/base/test/worker.js')
worker.addEventListener('message', function(e) {
switch (e.data.name) {
case 'pass':
test(e.data.title, function() {})
break
case 'pending':
test(e.data.title)
break
case 'fail':
test(e.data.title, function() {
var err = new Error(e.data.message)
err.stack = e.data.stack
throw err
})
break
case 'end':
mochaRun()
break
}
})
importScripts('/node_modules/chai/chai.js')
importScripts('/node_modules/mocha/mocha.js')
importScripts('/base/node_modules/mocha/mocha.js')
importScripts('/base/node_modules/chai/chai.js')
mocha.setup('tdd')
self.assert = chai.assert
importScripts('/node_modules/promise-polyfill/promise.js')
importScripts('/node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js')
importScripts('/dist/fetch.umd.js')
importScripts('/test/test.js')
importScripts('/base/dist/fetch.umd.js')
importScripts('/base/test/test.js')
function title(test) {
return test.fullTitle().replace(/#/g, '')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册