I know this is, in a way, a duplicate question, but none of the tips I've found so far helped, which is why I decided to ask again.
I created a simple test in Mocha, and when I try to run it I keep getting the unexpected token import
error. I've tried many different solutions found here and elsewhere, but none of them seem to be relevant to my case. Since I'm a junior level programmer, I did not understand all the answers I've found and thus I'm unable to list them all here. The tip that was given most often, though, was to use --compilers js:babel-core/register.
This, however, did not work in my case. Below is my package.json
:
`{
"name": "beer-guru",
"version": "1.0.0",
"description": "A simple app displaying info about various beers",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --inline --hot --open",
"prettier": "prettier --single-quote --write ./app/**/*.js",
"lint": "eslint **/*.js",
"test": "mocha **/*.test.js"
},
"keywords": [
"React.js"
],
"author": "Maciek Maslowski",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.4",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^4.1.2",
"react-router-dom": "^4.1.2",
"styled-components": "^2.1.1",
"styled-tools": "^0.1.4"
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.2.10",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"eslint": "^4.4.1",
"eslint-loader": "^1.9.0",
"eslint-plugin-react": "^7.2.1",
"expect": "21.0.2",
"html-webpack-plugin": "^2.26.0",
"mocha": "3.5.3",
"prettier": "^1.5.3",
"react-redux": "5.0.6",
"redux": "3.7.2",
"supertest": "3.0.0",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
}
}`
my .babelrc
:
"presets": [
"es2015", "react", "env"
],
"plugins": ["transform-class-properties"]
and my webpack.config.js
:
var HtmlWebpackPlugin = require('html-webpack-plugin');
var HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: [
'./app/index.js'
],
devServer: {
historyApiFallback: true
},
output: {
path: __dirname + '/dist',
filename: "index_bundle.js"
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loaders: ["babel-loader", "eslint-loader"]}
]
},
plugins: [HtmlWebpackPluginConfig]
}
Does anyone here have any idea if it's possible to run Mocha tests with this config at all? And if so, does anyone know how?
Many thanks for all tips!