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

Teardown functions should run in reverse order #695

Closed
tobias-walle opened this issue Aug 31, 2020 · 0 comments · May be fixed by tapjs/libtap#50
Closed

Teardown functions should run in reverse order #695

tobias-walle opened this issue Aug 31, 2020 · 0 comments · May be fixed by tapjs/libtap#50

Comments

@tobias-walle
Copy link

tobias-walle commented Aug 31, 2020

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:

  1. drop-database
  2. close-connection

I would expect that they are run in the reverse order:

  1. close-connection
  2. 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
    
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

Successfully merging a pull request may close this issue.

1 participant