Skip to content

Commit

Permalink
fix: make a single webpack bundle
Browse files Browse the repository at this point in the history
Prior to this commit there was a webpack bundle created for every test
file. That lead to very high memory usage when running the Browser tests.
Now there's a single bundle.
  • Loading branch information
vmx committed Mar 6, 2018
1 parent 57c9554 commit f1e2850
Show file tree
Hide file tree
Showing 4 changed files with 29 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 and 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
13 changes: 11 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 @@ -47,6 +48,13 @@ function getConfig (isWebworker, ctx) {
pattern: pattern,
included: !isWebworker
}))
// Preprocess every file that is used as a test file for Karma. By default
// that's a single entry point, but it could also be a single test that
// is given as command line parameter
const preprocessors = getPatterns(ctx).reduce((acc, pattern) => {
acc[pattern] = ['webpack', 'sourcemap']
return acc
}, {})

const fixtureFiles = [{
pattern: 'test/fixtures/**/*',
Expand All @@ -70,6 +78,7 @@ function getConfig (isWebworker, ctx) {
frameworks: isWebworker ? ['mocha-webworker'] : ['mocha'],
logLevel: ctx.verbose ? 'debug' : 'error',
client: getClient(isWebworker, ctx),
preprocessors: preprocessors,
mochaOwnReporter: {
reporter: 'spec'
},
Expand Down

0 comments on commit f1e2850

Please sign in to comment.