diff --git a/config.js b/config.js index d28ee925b1..c20a0dbcd1 100644 --- a/config.js +++ b/config.js @@ -52,7 +52,7 @@ config = Object.assign({}, config, { // ---------------------------------- // Compiler Configuration // ---------------------------------- - compiler_devtool: (__DEV__ || __TEST__) && 'cheap-source-map' || __STAGING__ && 'source-map', + compiler_devtool: __DEV__ && 'cheap-source-map' || __TEST__ && 'inline-source-map' || __STAGING__ && 'source-map', compiler_globals: { process: { env: { diff --git a/docs/app/index.js b/docs/app/index.js index 9ff7e1e41f..11364ca297 100644 --- a/docs/app/index.js +++ b/docs/app/index.js @@ -24,7 +24,7 @@ if (__DEV__) { ReactDOM.unmountComponentAtNode(mountNode) try { - render(import('./routes').default) + render(require('./routes').default) document.scrollingElement.scrollTop = scrollTop document.scrollingElement.scrollLeft = scrollLeft } catch (e) { diff --git a/karma.conf.js b/karma.conf.js index 0dea5f337d..f72290363c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,49 +1,48 @@ const { argv } = require('yargs') + const config = require('./config') const webpackConfig = require('./webpack.config') -module.exports = (karmaConfig) => { - karmaConfig.set({ - basePath: process.cwd(), - browsers: ['PhantomJS'], - singleRun: !argv.watch, - reporters: ['mocha', 'coverage'], - files: [ - './test/tests.bundle.js', - ], - formatError(msg) { - let haveSeenStack = false - return msg - .split('\n') - .reduce((list, line) => { - // filter out node_modules - if (/~/.test(line)) return list +const formatError = (msg) => { + let haveSeenStack = false + return msg + .split('\n') + .reduce((list, line) => { + // filter out node_modules + if (/~/.test(line)) return list + + // indent the error beneath the it() message + let newLine = ' ' + line - // indent the error beneath the it() message - let newLine = ' ' + line + if (newLine.includes('webpack:///')) { + if (haveSeenStack === false) { + const indent = newLine.slice(0, newLine.search(/\S/)) + newLine = `\n${indent}Stack:\n${newLine}` + haveSeenStack = true + } - if (newLine.includes('webpack:///')) { - if (haveSeenStack === false) { - const indent = newLine.slice(0, newLine.search(/\S/)) - newLine = `\n${indent}Stack:\n${newLine}` - haveSeenStack = true - } + // remove webpack:/// + newLine = newLine.replace('webpack:///', '') - // remove webpack:/// - newLine = newLine.replace('webpack:///', '') + // remove bundle location, showing only the source location + newLine = newLine.slice(0, newLine.indexOf(' <- ')) + } - // remove bundle location, showing only the source location - newLine = newLine.slice(0, newLine.indexOf(' <- ')) - } + return list.concat(newLine) + }, []) + .join('\n') +} - return list.concat(newLine) - }, []) - .join('\n') +module.exports = (karmaConfig) => { + karmaConfig.set({ + basePath: process.cwd(), + browsers: ['PhantomJS'], + client: { + mocha: { + reporter: 'html', // change Karma's debug.html to mocha web reporter + ui: 'bdd', + }, }, - frameworks: [ - 'phantomjs-shim', - 'mocha', - ], coverageReporter: { reporters: [ { type: 'lcov', dir: 'coverage', subdir: '.' }, @@ -51,28 +50,30 @@ module.exports = (karmaConfig) => { ], includeAllSources: true, }, + files: [ + './test/tests.bundle.js', + ], + formatError, + frameworks: ['phantomjs-shim', 'mocha'], + reporters: ['mocha', 'coverage'], preprocessors: { // do not include 'coverage' preprocessor for karma-coverage // code is already instrumented by babel-plugin-__coverage__ - '**/*.bundle.js': ['webpack'], - }, - client: { - mocha: { - reporter: 'html', // change Karma's debug.html to mocha web reporter - ui: 'bdd', - }, + './test/tests.bundle.js': ['webpack', 'sourcemap'], }, + singleRun: !argv.watch, webpack: { devtool: config.compiler_devtool, - module: Object.assign({}, webpackConfig.module, { - loaders: [ + entry: './test/tests.bundle.js', + module: { + rules: [ + ...webpackConfig.module.rules, { test: /sinon\.js$/, - loader: 'imports?define=>false,require=>false', + loader: 'imports-loader?define=>false,require=>false', }, - ...webpackConfig.module.loaders, ], - }), + }, plugins: webpackConfig.plugins, resolve: Object.assign({}, webpackConfig.resolve, { alias: Object.assign({}, webpackConfig.resolve.alias, { diff --git a/package.json b/package.json index 3d9165fb91..ef60f807e2 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "gulp-plumber": "^1.0.1", "gulp-util": "^3.0.6", "html-webpack-plugin": "^2.24.0", - "imports-loader": "^0.7.0", + "imports-loader": "^0.7.1", "js-beautify": "^1.6.8", "json-loader": "^0.5.3", "karma": "^1.4.0", @@ -108,7 +108,8 @@ "karma-mocha-reporter": "^2.2.1", "karma-phantomjs-launcher": "^1.0.0", "karma-phantomjs-shim": "^1.4.0", - "karma-webpack-with-fast-source-maps": "^1.9.2", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^2.0.3", "mocha": "^3.2.0", "node-sass": "^4.1.1", "phantomjs-prebuilt": "^2.1.7", diff --git a/test/specs/lib/isBrowser-test.js b/test/specs/lib/isBrowser-test.js index 621e152fa2..7be371857d 100644 --- a/test/specs/lib/isBrowser-test.js +++ b/test/specs/lib/isBrowser-test.js @@ -7,12 +7,12 @@ describe('isBrowser', () => { }) it('should return false when there is no document', () => { - require('imports?document=>undefined!src/lib/isBrowser').default.should.be.false() - require('imports?document=>null!src/lib/isBrowser').default.should.be.false() + require('imports-loader?document=>undefined!src/lib/isBrowser').default.should.be.false() + require('imports-loader?document=>null!src/lib/isBrowser').default.should.be.false() }) it('should return false when there is no window', () => { - require('imports?window=>undefined!src/lib/isBrowser').default.should.be.false() - require('imports?window=>null!src/lib/isBrowser').default.should.be.false() + require('imports-loader?window=>undefined!src/lib/isBrowser').default.should.be.false() + require('imports-loader?window=>null!src/lib/isBrowser').default.should.be.false() }) }) diff --git a/webpack.umd.config.js b/webpack.umd.config.js index 412f3892e9..369ccb18ac 100644 --- a/webpack.umd.config.js +++ b/webpack.umd.config.js @@ -35,7 +35,7 @@ const webpackUMDConfig = { ], module: { noParse: webpackConfig.module.noParse, - loaders: webpackConfig.module.loaders, + rules: webpackConfig.module.rules, }, }