I'm trying to implement unit tests for my code by using Karma + karma-typescript + mocha.
The following code is based on this example. The only differences are that I use mocha instead of jasmine and amd instead of commonjs.
The directory structure
.
|-- src
| |-- core
| | |-- Class1.ts
..
|-- test
| |-- Test.spec.ts
..
| -- karma.conf.js
| -- tsconfig.json
Karma.conf.js
module.exports = function (config) {
config.set({
frameworks: ["mocha", "karma-typescript"],
files: [
{pattern: 'src/**/*.ts'},
{pattern: 'test/**/*.spec.ts'}
],
preprocessors: {
'src/**/*.ts': ['karma-typescript']
},
karmaTypescriptConfig: {
tsconfig: "./tsconfig.json"
},
customLaunchers: {
ChromeNoSandbox: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
reporters: ['karma-typescript'],
logLevel: config.LOG_DEBUG,
browsers: ["ChromeNoSandbox"],
singleRun: true
})
};
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"lib": [ "es2015", "dom" ],
"sourceMap": true,
"removeComments": true,
"alwaysStrict": true,
"noImplicitAny": true
},
"exclude": [
"build",
"node_modules",
"dist"
]
}
And a really simple test
describe("Test", () => {
it("Should do some cool stuff", () => {
console.log('Cool stuff');
})
});
Executing karma results in this warning:
"Warning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit"
I think that using amd instead of commonjs may cause the problem but I have no idea why.