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

Use of onCleanup() when test returns a promise #765

Closed
devinivy opened this issue Oct 6, 2017 · 4 comments
Assignees
Milestone

Comments

@devinivy
Copy link
Member

@devinivy devinivy commented Oct 6, 2017

Currently the API to register a cleanup routine for a test is tangled with the use of callback-style tests (done()). That's because onCleanup is passed as the second argument to each test, and this check forbids the test to both return a promise and receive any arguments.

It would be very useful to be able to register a cleanup routine and use the promise API, especially with hapi now embracing async/await.

I do not know the ideal API for this, but here's something to get started with.

it('works great.', async function () {

    this.onCleanup(async () => rimraf('some/file.txt'));

    await otherTestActivities();
});

Another option is to loosen the restriction, and only complain if done() is actually called in a test that returns a promise. Then it could be ignored as the first argument, and onCleanup could still be utilized.

@geek

This comment has been minimized.

Copy link
Member

@geek geek commented Oct 6, 2017

@devinivy I'm moving onCleanup to the async/await style and will come on a single flags object that will be passed in... let me know what you think:

it('works great.', async (flags) {

    flags.onCleanup(async () => rimraf('some/file.txt'));

    await otherTestActivities();
});
@geek geek added the request label Oct 6, 2017
@devinivy

This comment has been minimized.

Copy link
Member Author

@devinivy devinivy commented Oct 6, 2017

Looks good to me! What else might go on flags?

@geek

This comment has been minimized.

Copy link
Member

@geek geek commented Oct 12, 2017

@devinivy flags will also have notes and in the future mustCall

@geek geek added this to the 15.0.0 milestone Oct 12, 2017
@geek geek added breaking changes feature and removed request labels Oct 12, 2017
@geek geek self-assigned this Oct 12, 2017
@AdriVanHoudt

This comment has been minimized.

Copy link
Contributor

@AdriVanHoudt AdriVanHoudt commented Oct 12, 2017

how about ?

it('works great.', async (flags) {

    await otherTestActivities();
}, async () => rimraf('some/file.txt'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.