Jasmine karma Uncaught ReferenceError: exports is not defined

Viewed 1288

I've created Jasmine test in typescript file for react tsx unit test and I'm using webpack for compiling typescript file into js. Added Karma.config.js file with all required settings but i keep getting 'exports is not defined' error while running test using karma start command. Note: I'm using es6 with commonjs module and here is my tsconfig.js.

tsconfig.js

{
    "compilerOptions": 
     {
    "outDir": "wwwroot/js/",

    // Output source maps.
    "sourceMap": true,

    // Raise errors for implicit any.
    "noImplicitAny": false,

    // Works with system, and other module systems.
    "module": "commonjs",

    // Avoid fall through case in switch.
    "noFallthroughCasesInSwitch": true,

    // Raise errors for implicit return.
    "noImplicitReturns": true,

    // Raise errors for unused parameters.
    "noUnusedParameters": true,

    // Output version.
    "target": "es6",

    // Enable JSX support for React.
    "jsx": "react",

    //Enable strick null checks
    //"strictNullChecks": true,

    //Auto-recompile
    "watch": false
  },
    "exclude": [
    "node_modules"
    ]
}

Karma.config.js

var webpackConfig = require('./webpack.config.js');

module.exports = function(config) {
    config.set({

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

    frameworks: ['jasmine'],

    // List of files / patterns to load in the browser
    files: ['wwwroot/js/tests/specs/reducers/*.js'],

    // List of files to exclude
     exclude: [ ],

     preprocessors: {      'wwwroot/tests/specs/reducers/MappingConfigurationReducerTest.spec.tsx': ['webpack', 'sourcemap']            
        },

        webpack: webpackConfig,

        webpackMiddleware: {
            noInfo: true
        },

        reporters: ['progress'],

        // Web server port
        port: 9876,

        // enable / disable colors in the output (reporters and logs)
        colors: true,

        logLevel: config.LOG_INFO,
        autoWatch: true,

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

        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false,

        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: Infinity,

        htmlReporter: {
            outputFile: 'tests/result.html'
        }
    });
}

I've spent so much time in resolving this issue but no luck. Any help would be appreciated. Thanks

0 Answers
Related