Karma + PhantomJS - 窗口未定义

时间:2016-07-08 03:07:14

标签: phantomjs karma-runner karma-mocha

我使用Karma和PhantomJS作为无头浏览器。出于某种原因,我不断收到错误消息,说明窗口未定义。

我的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
    }
  });
};

这是我得到的错误:

enter image description here

即使我使用PhantomJS作为启动器,我也不确定为什么窗口对象不可用。任何帮助将不胜感激。

0 个答案:

没有答案