ReferenceError: Can't find variable: require in karma

时间:2018-06-04 16:45:06

标签: javascript

When I try to run my karma.conf.js i'm geeting error ReferenceError: Can't find variable: require. Here is my configuration.

module.exports = function (config) {
  config.set({
   
    browsers: ['PhantomJS'],
    colors: true,
    client: {
      clearContext: false
    },
    failOnEmptyTestSuite: false,
    frameworks: [
      'mocha',
      'chai'
    ],
    files: [
      'tests/test.js',
      { pattern: 'tests/lib/*.js', included: false },
    ],
    preprocessors: {
      'tests/messageFormat.test.js': ['webpack', 'sourcemap'],
    },
    reporters:['spec', 'coverage'],
    coverageReporter: {
      reporters: [
        { type: 'text' },
        { type: 'html', subdir: 'html' }
      ],
    },
    webpack: {
      cache: true,
      devtool: 'inline-source-map',
      module: {
        loaders: [
          {
            enforce: 'pre',
            test: /.spec\.js$/,
            include: /tests/,
            exclude: /node_modules/,
            use: [{ loader: 'babel-loader' }]
          },
          {
            enforce: 'pre',
            test: /\.js$/,
            include: /js/,
            exclude: /node_modules/,
            use: [{ loader: 'istanbul-instrumenter-loader', query: { esModules: true } }]
          },

          {
            test: /\.js$/,
            include: /js/,
            exclude: /node_modules|tests/,
            use: [{ loader: 'babel-loader' }]
          },
        ],
      },
    },
  });
};

var testsContext = require.context(".", true, /.test$/);
testsContext.keys().forEach(testsContext);

And also I have some clouser functions and I want to import that functions to write test cases. So, How I can import globally.

0 个答案:

没有答案