From 233708c4b5adb8d2f406aa7f236cfa3699436936 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 7 Feb 2017 09:40:20 -0800 Subject: [PATCH] feat(test): enable tests in webworkers by default --- bin/test | 9 ++++++++- config/eslintrc.yml | 2 ++ config/karma.conf.js | 23 ++--------------------- fixtures.js | 6 +++--- tasks/test/browser.js | 41 ++++++++++++++++++++++++++++++++++------- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/bin/test b/bin/test index f88c501d5..0e467400d 100755 --- a/bin/test +++ b/bin/test @@ -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 { diff --git a/config/eslintrc.yml b/config/eslintrc.yml index 40951c9ef..fc6421e84 100644 --- a/config/eslintrc.yml +++ b/config/eslintrc.yml @@ -2,6 +2,8 @@ extends: standard parserOptions: sourceType: 'script' +globals: + self: true rules: strict: [2, 'safe'] curly: 'error' diff --git a/config/karma.conf.js b/config/karma.conf.js index 67439aed2..2cb5267db 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -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'] @@ -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'] @@ -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'] }, diff --git a/fixtures.js b/fixtures.js index 4ba0f06e4..33527c3b1 100644 --- a/fixtures.js +++ b/fixtures.js @@ -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) diff --git a/tasks/test/browser.js b/tasks/test/browser.js index cd3881ce3..b75d2ec1f 100644 --- a/tasks/test/browser.js +++ b/tasks/test/browser.js @@ -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') @@ -20,7 +27,7 @@ module.exports = (gulp) => { }) gulp.task('test:karma:webworker', (done) => { - if (!util.env.webworker) { + if (util.env.dom) { return done() } @@ -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) => {