I have a test that looks like the following (Pseudocode):
const db = connectToDatabase ( ) ;
t . teardown ( ( ) => db . drop ( ) ) ; // drop-database
const connection = db . connect ( ) ;
t . teardown ( ( ) => connection . close ( ) ) ; // close-connection
If I run the test I get an error, because I can't drop the database with open connections.
This is because tap runs the teardown functions in the order in which there are defined:
drop-database
close-connection
I would expect that they are run in the reverse order:
close-connection
drop-database
This way all connections would be closed before the database is dropped. This would also match the behavior of other test runners:
ava (must be configured, default in the next major release) Add ability to reverse the order of teardown steps avajs/ava#2495
jest. I didn't find good documentation explaining this but if I run:
beforeAll(() => console.log('Before each 1'))
afterAll(() => console.log('After all 1'))
beforeAll(() => console.log('Before each 2'))
afterAll(() => console.log('After all 2'))
it('should test', () => console.log('Test'))
It logs:
Before each 1
Before each 2
Test
After all 2
After all 1
I have a test that looks like the following (Pseudocode):
If I run the test I get an error, because I can't drop the database with open connections.
This is because tap runs the teardown functions in the order in which there are defined:
drop-databaseclose-connectionI would expect that they are run in the reverse order:
close-connectiondrop-databaseThis way all connections would be closed before the database is dropped. This would also match the behavior of other test runners: