1

我在 Windows 上运行一个 Aurelia 项目,我想用 PhantomJS 运行 Karma。我在这里的骨架项目中也有类似的 JSPM 和 Babel 。

[karma]: No captured browser, open http://localhost:9876/
[karma]: Karma v0.13.22 server started at http://localhost:9876/
[launcher]: Can not load "PhantomJS"!
  RangeError: Maximum call stack size exceeded
    at XXX\node_modules\di\lib\injector.js:119:19
    at Array.forEach (native)
    at XXX\node_modules\di\lib\injector.js:115:27
    at Array.forEach (native)
    at new Injector (XXX\node_modules\di\lib\injector.js:104:11)
    at createChild (XXX\node_modules\di\lib\injector.js:93:12)
    at module.(anonymous function) (XXX\node_modules\karma\lib\config.js:198:31)

这是我的 karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jspm', 'jasmine'],
    plugins: [
        'karma-babel-preprocessor',
        'karma-jspm',
        'karma-jasmine',
        'karma-phantomjs-launcher'
    ],
    jspm: {
      loadFiles: ['src/**/*.js', 'test/**/*.js'],
      serveFiles: ['src/**/*.js'],
      paths: {
        '*': '*',
        'github:*': 'jspm_packages/github/*',
        'npm:*': 'jspm_packages/npm/*'
      }
    },
    preprocessors: {
     'test/**/*.js': ['babel'],
     'src/**/*.js': ['babel']
    },
    'babelPreprocessor': {
      options: {
        sourceMap: 'inline',
        moduleIds: false,
        optional: [
          'es7.decorators',
          'es7.classProperties'
        ]
      }
    },

    defaultJSExtensions: true,
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    proxies : {
        '/src/': '/base/src/',
        '/jspm/': '/base/jspm/'
    },
    browsers: ['PhantomJS'],
    customLaunchers: {
        'PhantomJS': {
            base: 'PhantomJS',
            options: {
              settings: {
                webSecurityEnabled: false
              },
            },
            flags: ['--load-images=true'],
            // debug: true
        }
     },
     phantomjsLauncher: {
        exitOnResourceError: true
     },
    singleRun: false
  });
};

这是我的 gulp 文件:

var gulp = require('gulp');
var Karma = require('karma').Server;
/**
 * Run test once and exit
 */

var karmaConf = __dirname + '/../../karma.conf.js';
gulp.task('test', function(done) {
  new Karma({
    configFile: karmaConf,
    singleRun: false
  }, done).start();
});
/**
 * Watch for file changes and re-run tests on each change
 */
gulp.task('tdd', function(done) {
  new Karma({
    configFile: karmaConf
  }, done).start();
});

/**
 * Run test once with code coverage and exit
 */
gulp.task('cover', function(done) {
  new Karma({
    configFile: karmaConf,
    singleRun: true,
    reporters: ['coverage'],
    preprocessors: {
      'test/**/*.js': ['babel'],
      'src/**/*.js': ['babel', 'coverage']
    },
    coverageReporter: {
      includeAllSources: true,
      instrumenters: {
        isparta: require('isparta')
      },
      instrumenter: {
        'src/**/*.js': 'isparta'
      },
      reporters: [
        { type: 'html', dir: 'coverage' },
        { type: 'text' }
      ]
    }
  }, done).start();
});

我的版本:

  • JSPM: 0.16.15
  • NPM: 3.8.3
  • 吞咽: 3.9.1
  • 业力: 0.13.22

我确实有我的 PhantomJS 路径集(正在运行>phanthomjs)。

4

0 回答 0