R
R
Ramil2016-05-07 17:19:21
webpack
Ramil, 2016-05-07 17:19:21

How to run a test with webpack + karma?

I'm trying to run tests in karma. I am getting an error:

SyntaxError: Use of reserved word 'export'
at D:/projects/florida/src/index.spec.js:8143 <- webpack:///src/index.js:3:0

The error seems to be typical, but I did not find a solution. I use babel in my code. I tried to include both polyfills and babel runtimes, but to no avail. Karma config is like this:
"use strict";

const root = __dirname + "/src";

const params = {
  basePath: 'src',
  files: [
    "**/*.spec.js"
  ],
  reporters: ["mocha"],
  frameworks: ["mocha", "chai"],
  preprocessors: {
    "**/*.spec.js": ["webpack", "sourcemap"]
  },
  browsers: ["PhantomJS"],
  colors: true,
  singleRun: true,
  webpackMiddleware: {
    noInfo:true
  }
};

params.plugins = [
  "karma-webpack",
  "karma-mocha",
  "karma-chai",
  "karma-phantomjs-launcher",
  "karma-mocha-reporter",
  "karma-sourcemap-loader"
];

params.webpack = {
  module: {
    preLoaders: [
      {
        test: /\.spec\.js$/,
        include: root,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          "presets": ["es2015"],
        }
      }
    ],
    loaders: [
      {
        test: /\.js$/,
        include: root,
        exclude: /node_modules/,
        loader: "babel",
        query: {
          "presets": ["es2015"]
        }
      }
    ]
  },
  resolve: {
    modulesDirectories: ["node_modules"],
    extensions: ["", ".js"]
  },
  devtool: "inline-source-map",
  cache: true
};

module.exports = function(config) {
  config.set(params);
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question