4

我第一次尝试使用 Karma + Mocha。

主要条件是在没有任何 GUI 的 Docker 容器中运行单元测试。我没有任何浏览器,我唯一的选择是使用 PhantomJS。

我已经配置了所有必要的插件、配置等,但我收到以下错误:

ReferenceError:找不到变量:导出

在测试运行之前,我使用 Babel 将 JavaScript 源代码构建到“build”目录,然后从那里启动 Karma。

什么可能导致这个问题?

这是我的 karma.conf.js:

// Karma configuration
// Generated on Mon Apr 25 2016 13:04:28 GMT+0300 (RTZ 2 (зима))
const path = require('path');
const webpack = require('webpack');

module.exports = function(config) {
  var confBuilder = require('./webpack.config');

  confBuilder.module.loaders.push({
      test: /\.jsx$/,
      loader: 'isparta',
      include: path.resolve('src'),
  });
  confBuilder.devtool = 'inline-source-map';

  config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'/*'jasmine' /*, 'requirejs'*/],


// list of files / patterns to load in the browser
files: [
  {pattern: 'build/utils/*.js', load: false}
],



// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
  'tests.webpack.js': ['webpack', 'sourcemap'],
  'build/utils/*.js': ['babel']
},



// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage', 'jenkins'],

plugins: [
    require('karma-webpack'),
    require('karma-mocha'),
    require('karma-chai'),
    require('karma-mocha-reporter'),
    require('karma-jenkins-reporter'),
    require('karma-chrome-launcher'),
    require('karma-sourcemap-loader'),
    require('karma-coverage'),
    require('karma-phantomjs-launcher'),
    require('karma-requirejs'),
    require('karma-babel-preprocessor')
],

webpack: confBuilder,

webpackServer: {
    noInfo: true,
},

coverageReporter: {
    check: {
        global: {
            statements: 86,
            branches: 80,
            functions: 95,
            lines: 40,
        },
    },
},

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
autoWatch: true,
  })
}
4

0 回答 0