I have typescript code and typescript jasmine tests running within Karma. I can run the tests from the command-line (using Karma), and also run the tests from the ReSharper test runner. Presumably I could also run the tests using Karma Test Adapter VS extension or VS Adapter for Karma. So, lots of options for running the tests.
My question is: How do I debug the tests, in the VS debugger?
I was able to get Visual Studio debugging of typescript jasmine tests, running in Karma, working. Wow, that's a mouthful.
Here's how I did it:
npm install -g karma karma-chrome-launcher karma-ie-launcher jasmine-core karma-jasmine karma-jasmine-html-reporter
npm install -g phantomjs karma-phantomjs-launcher
karma.conf.js
, add support for serving the required sourcemap and typescript files. Here's mine:module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'dist/**/*.js',
'test/out/**/*.js',
// Key addition to support debugging typescript tests
// Enable serving (but don't include as scripts) sourcemap and typescript files
{pattern: '**/*.js.map', included: false},
{pattern: '**/*.ts', included: false}
],
reporters: ['html', 'progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS']
});
}
karma start --browsers=IE --reporters=html
After that, you should see a "Script Documents" folder in Solution Explorer, and you should be able to put breakpoints in your typescript, run the tests in your browser, and step through your typescript code.
It turns out that all these steps also work for debugging Typescript tests and code in Chrome - just change step 4 to:
karma start --browsers=Chrome --reporters=html
(skip step 5) then open Chrome developer tools to debug the typescript in chrome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With