1
votes

I am new to gulp and karma tool.I have searched google and worked on small testcases and executed successfully.

In karma we are configuring the unit testcases js files that are to be tested and run using the command 'start karma karma.conf.js'

In gulp we are configuring the karma config file and execute using the command 'gulp test'

what benefits we are getting while running a gulp test over karma directly?

2

2 Answers

3
votes

One advantage of using gulp is that you can then orchestrate more complicated tasks based on that task. For example, you might want a gulp task that first builds the project then executes the unit tests. You could then execute that with one command rather than two commands.

However if you're only running the gulp task that runs karma then there won't be any advantage in using gulp (other than the command being easier to type).

You can look at the Gulp Recipes page to see other tasks you can accomplish with gulp.

1
votes

The only thing I can really think of is getting gulp to source all the appropriate 3rd party JS files required to run the tests using something like wiredep. For example

var gulp = require('gulp'),
    Server = require('karma').Server,
    bowerDeps = require('wiredep')({
        dependencies: true,
        devDependencies: true
    }),
    testFiles = bowerDeps.js.concat([
        'src/**/*.js',
        'test/**/*.js'
    ]);

gulp.task('test', function(done) {
    new Server({
        configFile: 'karma.conf.js',
        files: testFiles,
        singleRun: true
    }, function(exitStatus) {
        if (exitStatus) {
            console.warn('Karma exited with status', exitStatus);
        }
        done();
    }).start();
});

Otherwise, you have to maintain the files array in your karma.conf.js file manually.