[英]Run Mocha specs from React app in a browser using Webpack and mocha-loader
I have a react
App for which I'd like to run its mocha
specs (unit-tests) in a browser. 我有一个我想在浏览器中运行其
mocha
规范(单元测试)的react
App。 I found this SO post and tried to apply same idea to my project. 我找到了这篇SO帖子,并尝试将相同的想法应用于我的项目。 I came up with the following
webpack
config file: 我想出了以下
webpack
配置文件:
const nodeExternals = require('webpack-node-externals');
const path = require('path');
const host = 'localhost';
const port = '8084';
module.exports = {
target: 'web',
externals: [nodeExternals()],
entry: './specs/index.js',
output: {
filename: 'debug.bundle.js',
path: path.join(__dirname, 'tests'),
publicPath: `http://${host}:${port}/tests`,
},
devServer: {
host,
port,
},
module: {
rules: [
{
test: /\.js$/,
loaders: ['react-hot-loader', 'babel-loader'],
enforce: 'pre',
},
{
test: /.+Spec\.js$/,
loaders: ['mocha-loader'],
},
{
test: /(\.css|\.scss)$/,
loader: 'null-loader',
exclude: [
/build/,
],
},
{
test: /(\.jpg|\.jpeg|\.png|\.gif)$/,
loader: 'null-loader',
},
],
},
};
And, after starting the server with: 并且,在使用以下命令启动服务器后:
webpack-dev-server --config webpack.config.test.js
I get the following error in console: 我在控制台中收到以下错误:
I've read that the problem might be with webpack-node-externals
but not really sure what's happening. 我读过,问题可能出在
webpack-node-externals
但不确定是怎么回事。 Any ideas? 有任何想法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.