Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

danielpacak
Copy link
Contributor

No description provided.

1. In the previous example, the Gulp's task complete callback was passed directly to the Server's constructor which is wrong.
2. There's new `deploy` task added to test and make sure that the Gulp's done callback is invoked with valid args.
3. Add PhantomJS browser to karma config.

Closes #22
@danielpacak
Copy link
Contributor Author

Hej Mistrzowie! Ktoś to zmerdżuje?

@carlthuringer
Copy link

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

@JoniJnm
Copy link

JoniJnm commented Jul 13, 2016

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();
        }
    });
});

@danielpacak
Copy link
Contributor Author

danielpacak commented Jul 14, 2016

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.

@deltamualpha
Copy link

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.

@johannesjo
Copy link

johannesjo commented Oct 7, 2016

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants