Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[bug] Cannot add hooks through require config #3176

Closed
c-vetter opened this issue Feb 28, 2023 · 0 comments
Closed

[bug] Cannot add hooks through require config #3176

c-vetter opened this issue Feb 28, 2023 · 0 comments

Comments

@c-vetter
Copy link

With AVA 5.2.0 on Windows, I just ran into pretty much this issue: #1944
…the only difference being that I don't want to setup something like a database but prepare the worker's state.

I have this config:

{
        "extensions": {
            "ts": "module",
            "tsx": "module"
        },
        "nodeArguments": [
            "--loader=tsx",
            "--require=global-jsdom/register"
        ],
        "require": [
            "./src/setupTests.ts"
        ]
    }

In setupTests.ts, I have this, basically:

import ava from "ava"
import { setup, teardown } from "..."

ava.before(() => setup())
ava.after(() => teardown())

If I read #1944 (comment) correctly, that's the correct approach for worker-global setup. However, running either npx ava or npm test (the script being ava --watch), I get this Error for each test file:

Error: All tests and hooks must be declared synchronously in your test file, and cannot be nested within other tests or hooks.

That does not happen if I remove the require config and add this to my test files (which is what I'm going with now):

import "../../setupTests"

This looks like a bug with the require config to me. Otherwise, I misunderstand how require and workers relate. In any case, some more documentation on what require is supposed to do or how it works would be nice. Maybe a recipe with a real use-case.

@avajs avajs locked and limited conversation to collaborators Mar 1, 2023
@novemberborn novemberborn converted this issue into discussion #3179 Mar 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant