lukeed / uvu

uvu is an extremely fast and lightweight test runner for Node.js and the browser
MIT License
2.96k stars 102 forks source link

Feature Request: Global before & after hooks #81

Open ASaiAnudeep opened 3 years ago

ASaiAnudeep commented 3 years ago

Having global before & after hooks that will run before & after all the tests/suites will help running tests that requires one/many global setups & one/many global teardowns.

Use Case: Running service level tests with pactum, where I need to start & stop a mock server before & after the test execution.

By the way, thank you for this awesome library. ❤️

lukeed commented 3 years ago

Thanks :)

Wouldn't pretest and posttest scripts work for this? Or running uvu programmatically

ASaiAnudeep commented 3 years ago

pretest and posttest doesn't work in my scenario. I need to have shared context between pretest, test and posttest.

Example:

before(() => { /* add reporters*/ });

/*
 suites/tests that uses above added reporters
*/

after(() => { /* end reporter*/ });

Not sure how to achieve this in pretest & posttest scripts.

Gameghostify commented 3 years ago

This would be super useful for setting up/terminating DB connections as well!

I'm having a problem where I want to tear down connections after the last test has run. Since I want to be able to run tests in isolation and with the CLI, a global hook that always runs after the last test is done would work really well here

Gameghostify commented 3 years ago

Maybe something like this?

Only a POC! If it gets implemented properly, it would probably look a little different

uvu.before should run before all suites, uvu.beforeEach should run before each suite uvu.after should run after all suites, uvu.afterEach should run before each suite

weepy commented 1 year ago

Any movement on this feature ?