Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

How to signal async completion in gulp 4.0? #23

Closed
liweiz opened this issue Jun 21, 2017 · 2 comments · Fixed by #31
Closed

How to signal async completion in gulp 4.0? #23

liweiz opened this issue Jun 21, 2017 · 2 comments · Fixed by #31

Comments

@liweiz
Copy link

liweiz commented Jun 21, 2017

While using Gulp 4.0 to write tests like this:

gulp.task('someTests', function () {
    gulp.src(filePath).pipe(ava({verbose: true}));
});

I got the error:

The following tasks did not complete: xxxx
Did you forget to signal async completion?

It turns out in 4.0:

Gulp tasks are asynchronous and Gulp uses async-done to wait for the task's completion. Tasks are called with a callback parameter to call to signal completion. Alternatively, Task can return a stream, a promise, a child process or a RxJS observable to signal the end of the task.

Warning: Sync tasks are not supported and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by Gulp.

Official doc

And there is a more detailed explanation on SO.

I picked the callback option from that SO answer:

  1. Call the callback function

This is probably the easiest way for your use case: gulp automatically passes a callback function to your task as its first argument. Just call that function when you're done:

gulp.task('message', function(done) {
    console.log("HTTP Server Started");
    done();
});

But when I tried to do this:

gulp.task('someTests', function (done) {
    gulp.src(filePath).pipe(ava({ verbose: true })).on('end', function () {
        done();
    });
});

The done function was never being called. I tried several times under different settings of my test file and was not successful. I also put a console.log before the done call, it was never being called, either. So it seems there is no 'end' emitted by pipe(ava({ verbose: true })). But I did not find a way to put a callback into the gulp-ava call.

Is it just me? Or I was doing it the wrong way?

Thanks in advance,

Liwei

@sindresorhus
Copy link
Member

Use Stack Overflow for support questions. This has nothing specifically to do with this plugin and is the same for all Gulp plugins.

@ffMathy
Copy link
Contributor

ffMathy commented Oct 9, 2019

This is actually a bug, so it DOES have something to do with this plugin. See #29.

There is no way to detect if ava ends currently.

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 a pull request may close this issue.

3 participants