Last active
May 6, 2018 07:03
-
-
Save veereshmeesala/592c1f309aade0ad1664ef4e7e8d8d75 to your computer and use it in GitHub Desktop.
Webpack + Mocha + Chai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpackConfig = require('./webpack.config'); | |
webpackConfig.devtool = 'inline-source-map'; | |
module.exports = function (config) { | |
config.set({ | |
browsers: [ 'PhantomJS' ], | |
singleRun: true, | |
frameworks: [ 'mocha', 'chai', 'sinon', 'sinon-chai' ], | |
files: [ | |
'*/*.spec.js' | |
], | |
plugins: [ | |
'karma-phantomjs-launcher', | |
'karma-chai', | |
'karma-mocha', | |
'karma-sourcemap-loader', | |
'karma-webpack', | |
'karma-mocha-reporter', | |
'karma-sinon', | |
'karma-sinon-chai' | |
], | |
preprocessors: { | |
'tests.webpack.js': [ 'webpack', 'sourcemap' ] | |
}, | |
reporters: [ 'mocha' ], | |
webpack: webpackConfig, | |
webpackServer: { | |
noInfo: true | |
}, | |
autoWatch: true | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webpack_mocha_chai2", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"dev": "WEBPACK_ENV=dev ./node_modules/.bin/webpack --watch --inline", | |
"build": "WEBPACK_ENV=build ./node_modules/.bin/webpack", | |
"test": "karma start", | |
"test:ci": "watch 'npm run test' src/" | |
}, | |
"author": "Veeresh Meesala", | |
"license": "MIT", | |
"devDependencies": { | |
"babel-core": "^6.24.0", | |
"babel-eslint": "^7.2.1", | |
"babel-loader": "^6.4.1", | |
"chai": "^3.5.0", | |
"core-js": "^2.4.1", | |
"eslint": "^3.18.0", | |
"eslint-loader": "^1.7.0", | |
"eslint-plugin-react": "^6.10.3", | |
"karma": "^1.5.0", | |
"karma-chai": "^0.1.0", | |
"karma-chai-plugins": "^0.8.0", | |
"karma-chai-sinon": "^0.1.5", | |
"karma-chrome-launcher": "^2.0.0", | |
"karma-mocha": "^1.3.0", | |
"karma-mocha-reporter": "^2.2.3", | |
"karma-phantomjs-launcher": "^1.0.4", | |
"karma-sinon": "^1.0.5", | |
"karma-sinon-chai": "^1.2.4", | |
"karma-sourcemap-loader": "^0.3.7", | |
"karma-webpack": "^2.0.3", | |
"react": "^15.4.2", | |
"watch": "^1.0.2", | |
"webpack": "^2.3.2", | |
"webpack-dev-server": "^2.4.2" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WebpackDevServer = require('webpack-dev-server'); | |
var env = process.env.WEBPACK_ENV; | |
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin; | |
var plugins = []; | |
plugins.push(new UglifyJsPlugin({ minimize: true })); | |
var host = '0.0.0.0'; | |
var port = '9000'; | |
var config = { | |
entry: './src/index.js', | |
devtool: 'source-map', | |
output: { | |
path: __dirname + '/lib', | |
filename: outputFile, | |
publicPath: __dirname + '/example' | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /(\.jsx|\.js)$/, | |
loader: 'babel', | |
exclude: /(node_modules|bower_components)/ | |
}, | |
{ | |
test: /(\.jsx|\.js)$/, | |
loader: "eslint-loader", | |
exclude: /node_modules/ | |
} | |
] | |
}, | |
plugins: plugins | |
}; | |
if (env === 'dev') { | |
new WebpackDevServer(webpack(config), { | |
contentBase: './example', | |
hot: true, | |
debug: true | |
}).listen(port, host, function (err, result) { | |
if (err) { | |
console.log(err); | |
} | |
}); | |
console.log('-------------------------'); | |
console.log('Local web server runs at http://' + host + ':' + port); | |
console.log('-------------------------'); | |
} | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment