gulp-karma icon indicating copy to clipboard operation
gulp-karma copied to clipboard

chore(gulp): use Gulp async task support and Karma API properly

Open danielpacak opened this issue 10 years ago • 6 comments

danielpacak avatar Sep 28 '15 12:09 danielpacak

Hej Mistrzowie! Ktoś to zmerdżuje?

danielpacak avatar Oct 06 '15 19:10 danielpacak

:+1: This is exactly what I needed to solve my issue with using the supplied examples in a CI environment.

carlthuringer avatar Nov 25 '15 20:11 carlthuringer

It still has problems. The server.start() kills the proccess when it ends (I don't know why)

gulp.task('test', function(done) {
    var server = new karma.Server({
        configFile: __dirname + '/test/karma.config.js',
        singleRun: true
    });

    server.on('run_complete', function (browsers, results) {
        if (results.error || results.failed) {
            done(new Error('There are test failures'));
        }
        else {
            done();
        }
    });

    server.start();
});

gulp.task('js', ['test'], function() {
    return gulp.src('app/**/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('public/js'));
});

The output (js task doesn't end):

user@vm:/var/www/test# gulp js
[12:02:56] Using gulpfile /var/www/test/gulpfile.js
[12:02:56] Starting 'test'...
DEPRECATED: use your own version of lodash, this will go away in [email protected]
DEPRECATED: use your own version of lodash, this will go away in [email protected]
13 07 2016 12:02:56.898:INFO [karma]: Karma v1.1.1 server started at http://localhost:8080/
13 07 2016 12:02:56.901:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
13 07 2016 12:02:56.908:INFO [launcher]: Starting browser PhantomJS
13 07 2016 12:02:57.212:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#U1iVuy2DZhVyemxmAAAA with id 18916034
 PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 SUCCESS (0.047 secs / 0.001 secs)
.
PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 SUCCESS (0.047 secs / 0.001 secs)
[12:02:57] Finished 'test' after 1.05 s
[12:02:57] Starting 'js'...
user@vm:/var/www/test#

I had to run the test in a child

gulp.task('test', function(done) {
    var child_process = require('child_process');
    child_process.exec('karma start test/karma.config.js', function (err, stdout){
        gutil.log(stdout);
        if (err) {
            throw new Error('There are test failures');
        }
        else {
            done();
        }
    });
});

JoniJnm avatar Jul 13 '16 10:07 JoniJnm

I'll have a look at this PR once again. It's been created a while ago and there're some changes in Karma and my understanding of Gulp.

danielpacak avatar Jul 14 '16 06:07 danielpacak

The example in the README.md was precisely what I needed to fix a delayed-timeout issue; it'd be nice to get that merged so it's easier to find when debugging that issue.

deltamualpha avatar Sep 23 '16 15:09 deltamualpha

@danielpacak if I use your solution inside of a task chain no tasks will be executed after the karma task is finished, as process.exit is being called by karma, if you provide no done callback as second parameter.

johannesjo avatar Oct 07 '16 15:10 johannesjo