Skip to content

Commit

Permalink
chore(package): update to webpack 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov committed Mar 24, 2017
1 parent 97849c5 commit 8fed8f8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 57 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion docs/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
97 changes: 49 additions & 48 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
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: '.' },
{ type: 'text-summary' },
],
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, {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions test/specs/lib/isBrowser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion webpack.umd.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const webpackUMDConfig = {
],
module: {
noParse: webpackConfig.module.noParse,
loaders: webpackConfig.module.loaders,
rules: webpackConfig.module.rules,
},
}

Expand Down

0 comments on commit 8fed8f8

Please sign in to comment.