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

How to know when all tests have completed? #189

Closed
coolaj86 opened this issue Aug 16, 2023 · 1 comment
Closed

How to know when all tests have completed? #189

coolaj86 opened this issue Aug 16, 2023 · 1 comment

Comments

@coolaj86
Copy link

I know this is mostly intended for unit tests, but I also have some tests to run that do DB calls.

Is there a way to know when all async functions have completed as to close the DB connection so the test file can exit?

@lorenzofox3
Copy link
Owner

lorenzofox3 commented Sep 2, 2023

you'll need to start the reporter yourself, or create a custom test harness. I could probably add an event as well.

have a look at pta cli file if you want an example.

for your usecase, I usually wrap the default test function into a custom one which setup db and close it after each test.

It allows me for example to inject a custom db service which run every single test in an isolated transaction so that I can run all the tests concurrently.

here with pg

import { test as ztest } from 'zora';
import { createDB } from 'db'; // my db abstraction
import { baseConfig, testDB } from './_config.js';

const testClient = createDB({
  ...baseConfig,
  transactionMode: 'no-commit',
  database: testDB,
  allowExitOnIdle: true,
  max: 10,
});

export const test = (description, specFn, options) =>
// here you can wrap into a try finally to close/release the db connection
  ztest(
    description,
    (assert) => specFn({ ...assert, db: testClient }),
    options
  );

and then I use this test function rather than zora's one

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

2 participants