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

How to signal async completion in gulp 4.0? #23

@liweiz

Description

@liweiz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions