Skip to content

Commit

Permalink
feat(test): enable tests in webworkers by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and dignifiedquire committed Feb 7, 2017
1 parent 15e15a8 commit 233708c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
9 changes: 8 additions & 1 deletion bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ require('../src/gulp-log')(gulp)
require('../gulp')(gulp, ['test'])

if (args.browser) {
gulp.start('test:browser')
if (args.dom) {
gulp.start('test:karma')
} else if (args.webworker) {
gulp.start('test:karma:webworker')
} else {
// run both dom and webworker tests by default
gulp.start('test:browser')
}
} else if (args.node) {
gulp.start('test:node')
} else {
Expand Down
2 changes: 2 additions & 0 deletions config/eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
extends: standard
parserOptions:
sourceType: 'script'
globals:
self: true
rules:
strict: [2, 'safe']
curly: 'error'
Expand Down
23 changes: 2 additions & 21 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

const webpackConfig = require('./webpack')
const timeout = require('./custom').timeout
const user = require('./user').customConfig

let userFiles = []
if (user.karma && user.karma.files) {
userFiles = user.karma.files
}

const files = [
'test/browser.js',
'test/**/*.spec.js',
{pattern: 'test/fixtures/**/*', watched: false, served: true, included: false}
].concat(userFiles)

let concurrency = 1
let reporters = ['mocha-own']
Expand Down Expand Up @@ -72,8 +60,8 @@ const launchers = {
let browsers = []

if (process.env.SAUCE_USERNAME &&
process.env.SAUCE_ACCESS_KEY &&
process.env.SAUCE) {
process.env.SAUCE_ACCESS_KEY &&
process.env.SAUCE) {
browsers = Object.keys(launchers)
concurrency = 3
reporters = ['progress', 'saucelabs']
Expand All @@ -86,13 +74,6 @@ if (process.env.SAUCE_USERNAME &&
module.exports = function (config) {
config.set({
basePath: process.cwd(),
frameworks: ['mocha'],
client: {
mocha: {
timeout: timeout
}
},
files: files,
preprocessors: {
'test/**/*.js': ['webpack', 'sourcemap']
},
Expand Down
6 changes: 3 additions & 3 deletions fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ module.exports = function loadFixtures (dirname, file, module) {
function syncXhr (url, module) {
let target
if (module) {
target = path.join('base', 'node_modules', module, 'test', url)
target = path.join('/base', 'node_modules', module, 'test', url)
} else {
target = path.join('base', 'test', url)
target = path.join('/base', 'test', url)
}
const request = new window.XMLHttpRequest()
const request = new self.XMLHttpRequest()
request.open('GET', target, false)
request.overrideMimeType('text/plain; charset=x-user-defined')
request.send(null)
Expand Down
41 changes: 34 additions & 7 deletions tasks/test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

const Server = require('karma').Server
const path = require('path')
const timeout = require('../../config/custom').timeout
const user = require('../../config/user').customConfig

let userFiles = []
if (user.karma && user.karma.files) {
userFiles = user.karma.files
}

module.exports = (gulp) => {
const util = require('gulp-util')
Expand All @@ -20,7 +27,7 @@ module.exports = (gulp) => {
})

gulp.task('test:karma:webworker', (done) => {
if (!util.env.webworker) {
if (util.env.dom) {
return done()
}

Expand Down Expand Up @@ -49,21 +56,41 @@ function karmaTest (webWorker, done) {

if (webWorker) {
config.frameworks = ['mocha-webworker']
config.client = {
mochaWebWorker: {
pattern: [
'test/browser.js',
'test/**/*.spec.js'
],
mocha: {
timeout: timeout
}
}
}
config.files = [{
pattern: 'test/browser.js', included: false
}, {
pattern: 'test/**/*.spec.js', included: false
}, {
pattern: 'test/fixtures/**/*', watched: false, served: true, included: false
}]
}].concat(userFiles)
} else {
config.frameworks = ['mocha']
config.files = [
'test/browser.js',
'test/**/*.spec.js',
{ pattern: 'test/fixtures/**/*', watched: false, served: true, included: false }
]
config.client = {
mochaWebWorker: {
pattern: [
'test/browser.js',
'test/**/*.spec.js'
]
mocha: {
timeout: timeout
}
}
config.files = [
'test/browser.js',
'test/**/*.spec.js',
{ pattern: 'test/fixtures/**/*', watched: false, served: true, included: false }
].concat(userFiles)
}

new Server(config, (code) => {
Expand Down

0 comments on commit 233708c

Please sign in to comment.