Unexpected marker import using karma with webpack and babel

I am trying to run karma tests using karma, webpack and babel. I feel like I'm set up correctly, but it seems that the test files are not overflowing.

karma.conf:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['mocha', 'chai'],
    files: [
      {pattern: 'src/**/*-test.js', watched: false}
    ],
    exclude: [
    ],
    preprocessors: {
      'src/**/*-test.js': ['webpack']
    },

    webpack: require("./webpack.config.js"),
    webpackMiddleware: {
      stats: 'errors-only'
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}

      

webpack.config:

module.exports = {
  entry: [
    'react-hot-loader/patch',
    'webpack/hot/only-dev-server',
    path.resolve(__dirname, 'src/index.js')
  ],
  output: {
    filename: 'bundle.js'
  },
  module: {
    rules: [
      { test: /\.(js|jsx)$/, exclude:  /(\/node_modules\/|test\.js$)/, use: 'babel-loader'},
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      { test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
      { test: /\.(png|woff|woff2|eot|ttf|svg)$/, use: 'url-loader?limit=100000' }
    ]
  },
  resolve: {
    extensions: ['.js', '.jsx']
  }   
};

      

My test file uses import syntax to import from chai and runs a simple test. taht expects true to be true, but when I run karma I get

unsached syntaxerror: unexpected token import

I had a similar question: Karma + Webpack (babel-loader) + ES6 "Unexpected token import"

but no luck. I'm pretty sure this is something simple in my configurations. Has anyone seen something like this?

this is a new project so use the latest packages, webpack2, etc.

Any ideas C

+3


source to share





All Articles