Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make a single webpack bundle #203

Merged
merged 1 commit into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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