Skip to content

test.serial.afterEach #1178

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

Closed
RafaelKr opened this issue Jan 11, 2017 · 4 comments
Closed

test.serial.afterEach #1178

RafaelKr opened this issue Jan 11, 2017 · 4 comments
Milestone

Comments

@RafaelKr
Copy link

It would be great if I could do this:

test.serial.afterEach(async (t) => {
  // run this only after all serial tests
});

// also for the other functions like before, beforeEach and afterEach

I want to run a test-file where some tests are serial to test functions which require a database and some tests should run in parallel. I would like to clear the database after each of the serial tests, but the others don't need it.

@mightyiam
Copy link
Contributor

Isn't it incidental that the tests you wish to run some code after are serial to each other?

@novemberborn
Copy link
Member

I assume currently the serial.afterEach callback is run after both serial and non-serial tests?

For your use case I'd suggest placing the serial tests in a separate file. It's an oddity of how the function chains are managed that you can type that combination.

I think it'd be confusing to allow callbacks specifically for serial tests, more so since there is no test.parallel.afterEach equivalent.

@RafaelKr
Copy link
Author

@novemberborn Okay, you're right, that would be confusing. I didn't see it like that yet.

It's not really a problem for me, because the afterEach doesn't take long. But it could be a problem, if the afterEach would take 5 seconds or more.

Maybe another solution would be to attach the metadata of the associated test to the t-variable. Then you could check there which type of test was/will be (before/after) called.

@novemberborn
Copy link
Member

Yes, those are potential issues, but easily solved by placing serial tests in separate files.

I've opened #1182 so that eventually we'd remove support for test.serial.afterEach()-style hooks. Thanks for raising this!

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