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.