oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.13k stars 2.67k forks source link

Test suite `beforeAll` is not executed #1688

Closed itsezc closed 1 year ago

itsezc commented 1 year ago

What version of Bun is running?

0.4.0

What platform is your computer?

WSL / Windows

What steps can reproduce the bug?

Use Surreal.JS with Bun:

import { beforeAll, it, describe, expect, afterAll } from 'bun:test';
import Surreal from 'surrealdb.js';

const TEST_DB = 'tests';
const db = new Surreal(process.env.SURREAL_HOST);

describe('Database', async () => {
    beforeAll(async () => {
        await db.signin({
            user: 'root',
            pass: 'root',
        });

        await db.use('test_namespace', TEST_DB);

        await db.query('DEFINE DATABASE tests');
        console.log('beforeAll');
    });

    afterAll(async () => {
        await db.query('REMOVE DATABASE tests');
        db.close();

        console.log('afterAll');
    });

    it('Database connection', async () => {
        expect(db).toBeDefined();
    });
});

What is the expected behavior?

I expect the code provided in beforeAll to be executed but there are no DB calls or console.logs

What do you see instead?

Only the afterAll is executed and logged

Additional information

No response

Jarred-Sumner commented 1 year ago

I think this is an issue with async

itsezc commented 1 year ago

I think this is an issue with async

Yup, when I move the logic from beforeAll into the parent describe (with async), everything seems to work as expected - even the afterAll works 🤔