create package.js
npm init -y
create tsconfig.json
tsc --init
install deps
npm i karma jasmine karma-webpack ts-loader typescript webpack karma-chrome-launcher karma-jasmine karma-sourcemap-loader
typings
typings install dt~jasmine --global --save
my.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: ['spec/main.spec.ts'],
preprocessors: {
'spec/main.spec.ts': ['webpack', 'sourcemap'],
},
webpack: {
resolve: {
extensions: ['', '.js', '.ts', '.tsx']
},
module: {
loaders: [
{test: /\.tsx?$/, loader: 'ts-loader'}
]
},
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true
},
devtool: 'inline-source-map',
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
spec/main.spec.ts
describe('testgroup', ()=> {
it('case1', ()=> {
expect(true).toBe(true);
})
})
run karma
karma start my.conf.js
to work source maps correctly you need patch node_modules/karma-webpack/index.js
// replace this
webpackOptions.output.filename = "[name]";
// by that
webpackOptions.output.filename = "[name].js";
// find this line
Plugin.prototype.readFile = function(file, callback) {
// insert this lines
var origFile = file;
file += '.js';
// Replace
this.waiting.push(process.nextTick.bind(process, this.readFile.bind(this, file, callback)));
// to that
this.waiting.push(process.nextTick.bind(process, this.readFile.bind(this, origFile, callback)));
This worked for me with the following updates:
npm install @types/jasmine --save-dev
instead oftypings install dt~jasmine --global --save
mime: { 'text/x-typescript': ['ts','tsx'] },
to the karma.conf.js file as mentioned above"sourceMap": true,
inside the compilerOptions in the tsconfig.json file