Skip to content

Commit

Permalink
Build a single webpack bundle only
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx committed Mar 3, 2018
1 parent 57c9554 commit f694aa6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/config/karma-webpack-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global TEST_DIR */
// This is webpack specific. It will create a single bundle
// out of `test/browser.js annd all files ending in ".spec.js" within the
// "test" directory and all its subdirectories.
'use strict'

// Load test/browser.js if it exists
try {
require(TEST_DIR + '/browser.js')
} catch (_err) {
// Intentionally empty
}

const testsContext = require.context(TEST_DIR, true, /\.spec\.js$/)
testsContext.keys().forEach(testsContext)
3 changes: 0 additions & 3 deletions src/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ module.exports = function (config) {
config.set({
frameworks: ['mocha'],
basePath: process.cwd(),
preprocessors: {
'test/**/*.js': ['webpack', 'sourcemap']
},
webpackMiddleware: {
noInfo: true
},
Expand Down
4 changes: 3 additions & 1 deletion src/config/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function webpackConfig (env) {
const libraryName = utils.getLibraryName(pkg.name)
const userConfig = user.webpack
const entry = user.entry
const environment = utils.getEnv(env).stringified
environment.TEST_DIR = JSON.stringify(path.join(process.cwd(), 'test'))

return merge(base, {
entry: [
Expand All @@ -27,7 +29,7 @@ function webpackConfig (env) {
path: utils.getPathToDist()
},
plugins: [
new webpack.DefinePlugin(utils.getEnv(env).stringified)
new webpack.DefinePlugin(environment)
]
}, userConfig)
})
Expand Down
8 changes: 6 additions & 2 deletions src/test/browser-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ function getPatterns (ctx) {
}

return [
'test/browser.js',
'test/**/*.spec.js'
// Karma needs a single entry point. That files will create a single bundle
// out of `test/browser.js` and `test/**/*.spec.js`
'node_modules/aegir/src/config/karma-webpack-bundle.js'
]
}

Expand Down Expand Up @@ -70,6 +71,9 @@ function getConfig (isWebworker, ctx) {
frameworks: isWebworker ? ['mocha-webworker'] : ['mocha'],
logLevel: ctx.verbose ? 'debug' : 'error',
client: getClient(isWebworker, ctx),
preprocessors: {
'node_modules/aegir/src/config/karma-webpack-bundle.js': ['webpack']
},
mochaOwnReporter: {
reporter: 'spec'
},
Expand Down

0 comments on commit f694aa6

Please sign in to comment.