4

I am using Karma and PhantomJS for a headless browser. For some reason, I keep getting an error saying window is not defined.

My karma.conf.js

var path = require('path');
var webpack = require('webpack');
var webpackConfig = require('./config/webpack/webpack.config');

webpackConfig.module = {
  loaders: [
    {
      test: /\.js$/,
      loader: 'babel',
      include: path.join(__dirname, 'app/frontend')
    },
    { test: /\.json$/, loader: 'json-loader' },
    { test: /\.css$/, loader: 'style!css?modules&importLoaders=1&localIdentName=[name]__[local]' },
    { test: /\.scss$/, loader: 'style!css?modules&importLoaders=1&localIdentName=[name]__[local]!resolve-url!sass?outputStyle=expanded' },
    { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' } // inline base64 URLs for <=8k images, direct URLs for the rest
  ],
  noParse: [
    /node_modules\/sinon\//
  ]
};

  module.exports = function (config) {
    config.set({
    browsers: [ 'PhantomJS' ],
    singleRun: true, //just run once by default
    frameworks: [ 'mocha' ], //use the mocha test framework
    files: [
    'app/frontend/.config/karma/test.bundle.js' //just load this file
    ],
    preprocessors: {
      'app/frontend/.config/karma/test.bundle.js': [ 'webpack',   'sourcemap' ] //preprocess with webpack and our sourcemap loader
    },
    reporters: [ 'dots' ], //report results in this format
    webpack: webpackConfig,
    colors: true,
    webpackServer: {
    noInfo: true
    },
    phantomjsLauncher: {
      exitOnResourceError: true
    }
  });
};

And here's the error I get:

enter image description here

I'm not sure why window object is not available even though I use PhantomJS as the launcher. Any help would be greatly appreciated.

0 Answers0