Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting for jasmine to end before going on #69

Closed
stefanschulz opened this issue Apr 5, 2016 · 10 comments
Closed

Waiting for jasmine to end before going on #69

stefanschulz opened this issue Apr 5, 2016 · 10 comments

Comments

@stefanschulz
Copy link

I have trouble figuring out how to wait for jasmine to be done. What I basically want to achieve is to have the tests be reported by Istanbul:

gulp.src('target/**/*Spec.js').pipe(jasmine()).pipe(istanbul.writeReports());

This does not work, as Instanbul starts writing reports while jasmine is still running. So I tried sequencing the tasks by introducing methods with callbacks like so:

function testAll(callback) {
    "use strict";
    gulp.src('target/**/*Spec.js')
        .pipe(jasmine())
        .on('end', callback);
}

My issue here is, when I use 'finish', the callback is invoked before jasmine is done. And wenn I use 'end', as suggested in another issue, the callback never gets invoked.
Any suggestion on what I am missing?

Thanks,
Stefan

Modules:
gulp-jasmine@2.3.0
jasmine@2.4.1
gulp@3.9.1

@jbblanchet
Copy link
Contributor

Hi,

There's 2 parts to your question. The first is about Istanbul. I've used gulp-istanbul and gulp-jasmine together successfully using 2 patterns. The new one documented in their readme and the older one. Just replace mocha with jasmine and it should work correctly.

The second part is about the end event not firing. I'm unable to reproduce your problem. Here's what I used, with your exact npm versions:

gulpfile.js:

var gulp = require("gulp");
var jasmine = require("gulp-jasmine");

gulp.task("default", () =>
    gulp.src("test.spec.js")
        .pipe(jasmine())
        .on("end", () => {
            console.log("We're done!");
        })
);

test.spec.js:

describe("a test", () => {
    it("works", () => {
        expect(1).toBe(1);
    });
});

@stefanschulz
Copy link
Author

Hi,

Thanks for looking into it.
I re-tried the tests and reduced it to only using jasmine, no istanbul. Unfortunately, the end-Event does not get emitted, so there has to be some issue elsewhere in the system (maybe the node version itself).
Anyway, thanks again for your support.

Best regards,
Stefan

@JaycobA
Copy link

JaycobA commented May 4, 2016

Hi,

I was able to reproduce the issue and found out that the 'end' event does not seem to be emitted when the stream is not returned. Not sure with your version of JS @jbblanchet, but maybe the stream is returned by default in your example.

When I return the stream, the 'end' event is emitted.

If I'm right - is this expected behaviour (return vs. no-return)?

@jbblanchet
Copy link
Contributor

@JaycobA: Got it! Thanks for taking the time to reproduce

You're right, when using a callback instead of returning the pipe it doesn't work. I must admit that I was a little stumped, and I still can't explain it, but I can rule out gulp-jasmine as the culprit. Try:

gulp.task("default", function (cb) {
    gulp.src("test.spec.js") // No gulp-jasmine
        .on("end", function () {
            console.log("We're done!");
            cb();
        });
});

and compare the behavior with:

gulp.task("default", function () {
    return gulp.src("test.spec.js") // No gulp-jasmine
        .on("end", function () {
            console.log("We're done!");
        });
});

@jbblanchet
Copy link
Contributor

OK, investigated the issue a little further, and it seems that the behaviour changed changed with version 3.8 of Gulp. Run your test with gulp 3.7, and it should work fine. Not sure why that is, I'll log a bug in the gulp repo.

@stefanschulz
Copy link
Author

stefanschulz commented May 6, 2016

Thanks for looking further into this issue. As going back to gulp 3.7 is no option, I tried using return, but it did not seem to help. What did help though, was adding a handler for the data event before the end handler. Although, the data event does nothing, the end event is emitted and the tests properly finish before going on.
So the code is now like:

function testAll(callback) {
    "use strict";
    gulp.src('target/**/*Spec.js')
        .pipe(jasmine())
        .on('data', () => {})
        .on('end', callback);
}

@jbblanchet
Copy link
Contributor

Just wanted to let you know that we're still working on a potential solution. If you want to understand why you need to add a data handler, have a look at #71.

@JaycobA
Copy link

JaycobA commented May 9, 2016

Thanks @jbblanchet, I really appreciate your efforts in solving this.

@jbblanchet
Copy link
Contributor

Sorry about that, forgot to come back here and let you know how we resolved the situation. There was a lot of discussion about the best approach, but in the end we went with adding a new event to the pipeline, which is jasmineDone. So .on('jasmineDone', callback) should provide the behavior you were looking for.

This has been released in 2.4. I'll close the issue but feel free to discuss it here if there's still a problem.

@stefanschulz
Copy link
Author

Thank you @jbblanchet. I'll apply this as soon as we update to 2.4.

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

No branches or pull requests

3 participants