Skip to content

Commit

Permalink
fix: don't show warning if test/browser.js doesn't exist
Browse files Browse the repository at this point in the history
Check if `test/browser.js` exist before webpack is initiated and require
it only if it really exist. This makes a warning go away that lead to
a lot of console output.

Fixes #204.
  • Loading branch information
vmx committed Mar 28, 2018
1 parent b42b7e7 commit 4785bce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/config/karma-webpack-bundle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* global TEST_DIR */
/* global TEST_DIR, TEST_BROWSER_JS */
// 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
if (TEST_BROWSER_JS) {
require(TEST_BROWSER_JS)
}

const testsContext = require.context(TEST_DIR, true, /\.spec\.js$/)
Expand Down
10 changes: 9 additions & 1 deletion src/config/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const merge = require('webpack-merge')
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')

const utils = require('../../utils')
const base = require('./base')
Expand All @@ -16,7 +17,14 @@ function webpackConfig (env) {
const userConfig = user.webpack
const entry = user.entry
const environment = utils.getEnv(env).stringified
environment.TEST_DIR = JSON.stringify(path.join(process.cwd(), 'test'))
const testDir = path.join(process.cwd(), 'test')
environment.TEST_DIR = JSON.stringify(testDir)
const browserJs = path.join(testDir, 'browser.js')
if (fs.existsSync(browserJs)) {
environment.TEST_BROWSER_JS = JSON.stringify(browserJs)
} else {
environment.TEST_BROWSER_JS = JSON.stringify('')
}

return merge(base, {
entry: [
Expand Down

0 comments on commit 4785bce

Please sign in to comment.