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

Global beforeAll / Execute some code only once before ALL test files #4565

Closed
Deilan opened this issue Sep 29, 2017 · 8 comments
Closed

Global beforeAll / Execute some code only once before ALL test files #4565

Deilan opened this issue Sep 29, 2017 · 8 comments

Comments

@Deilan
Copy link

Deilan commented Sep 29, 2017

Do you want to request a feature or report a bug?
feature

What is the current behavior?
Unable to execute some code only once before all test files, e. g. create a database, promisify functions, import reflect-metadata, etc.

What is the expected behavior?
Able to execute some before all test files.

@Deilan Deilan changed the title Hook before ALL test files Hook before ALL test files / Global beforeAll Sep 29, 2017
@Deilan Deilan changed the title Hook before ALL test files / Global beforeAll Global beforeAll / Execute some code only once before ALL test files Sep 29, 2017
@cpojer
Copy link
Member

cpojer commented Sep 29, 2017

beforeEach or using your own custom test environment will work. There is a PR to make that async, #4506.

@idangozlan
Copy link

@cpojer I can't find out how your response related to the issue.

@Deilan , I'm experiencing the same thing, is there any solution run beforeAll that runs only once even if im using multiple test files?

@SimenB
Copy link
Member

SimenB commented Apr 14, 2018

We have globalSetup these days: https://facebook.github.io/jest/docs/en/configuration.html#globalsetup-string

@voroshkov
Copy link

@SimenB is there an example of how globalSetup can be used?

@thymikee
Copy link
Collaborator

thymikee commented Nov 9, 2018

@voroshkov
Copy link

@thymikee, thanks! Is there a way I can use ES6 imports in the globalSetup script or in scripts it requires?

@thymikee
Copy link
Collaborator

thymikee commented Nov 9, 2018

Nope, only with babel-register if you fancy

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants