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)));
Also, you don't need to patch the
karma-webpack
package if you replacedevtool: 'inline-source-map',
withplugins: [
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i, // process .js and .ts files only
exclude: [ /node_modules/ ]
})
]
in the karma.conf.js file along with requiring webpack (
var webpack = require("webpack");
)