Reputation: 6961
I have an angular js project with a .Net/C# backend. Some of the JS has unit tests, but at least one team member feels like having to jump out to the command line is a high enough barrier where he doesn't want to write unit tests. So I'm trying to get them to run from within VS with Resharper.
The problem is that I have directives in there with html templates. Every resource I found about how to handle that is to use the ng-html2js preprocessor in karma. None of the Resharper documentation tells you directly how to point to a karma.conf file so that that stuff can happen, and I haven't found any resources that suggest there's an alternate way to handle this.
According to the Resharper docs, you can use an html test harness, but I haven't found anything that suggests you can run karma from a test harness. I inherited this project recently, and I'd like to start by trying to address objections by team members rather than telling them to just suck it up and do it.
Can anyone point me in the right direction (of how to launch karma with an html harness or how to do preprocessing some other way)?
Upvotes: 2
Views: 576
Reputation: 5981
We have almost the same setup in our project. The .net/c# backend, and a lot of client stuff (JS, scss, html). We run our build/test through Gulp.js. Gulp is a streaming build system, very fast - and easy to configure. Also has lots of plugins for common tasks.
To kick off the karma runner from gulp, you can create a task in your gulpfile like this:
var gulp = require('gulp');
var karma = require('karma').server;
/**
* Run test once and exit
*/
gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
Then we use a Visual Studio extension called Task Runner Explorer. This extension lets you execute any Gulp task or target inside Visual Studio. You can also bind any Gulp task or target to a Visual Studio event, such as Build and Solution Open. That way you can run certain tasks when you build your project or run Gulp Watch when the solution is opened.
Upvotes: 1