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

Async setupFiles #949

Closed
grydstedt opened this issue Apr 28, 2016 · 8 comments
Closed

Async setupFiles #949

grydstedt opened this issue Apr 28, 2016 · 8 comments

Comments

@grydstedt
Copy link

It would be useful to be able to wait for an asynchronous completion of a setupFiles module before starting tests. Is there a way to do that?

@cpojer
Copy link
Member

cpojer commented Apr 28, 2016

This is not possible. Can you elaborate on why you'd like to do this?

@grydstedt
Copy link
Author

I see, thanks. Just a an async function that preps the test environment that I can't make synchronous unfortunately.

@cpojer
Copy link
Member

cpojer commented Apr 28, 2016

I don't think we'll support this as it makes everything dealing with the setup a bit more messy.

The way I would suggest to work around this is something like this in your setupFile:

global.it = function(description, fn) {
  pit(description, () => {
    // Assuming it is a promise
    return loadEnvironmentAsync().then(
      () => fn()
    )
  });
}

This will make everyone of your tests async. If you are not using pit you can use it instead (by doing const it = global.it; beforehand to save the jasmine function before). Then you have to use the done flag to work with async operations.

Let me know if this isn't a satisfying solution

@jasonkuhrt
Copy link

I just hit a use-case for this where I needed to do some async logic to determine which host the test suite should be running against. I will rework my solution to have the script expose data in an ENV variable for now. Would have been nice to have this though : )

@jasonkuhrt
Copy link

jasonkuhrt commented Jan 22, 2018

Oh amazing #3832 (comment).

Thanks @xfumihiro!!

@xfumihiro
Copy link
Contributor

@jasonkuhrt happy coding! 😄

@spencerwilson
Copy link

See also: #11038

tl;dr Using ES modules, there's early support for awaiting async effects in setupFiles (and probably setupFilesAfterEnv, too). Might be a simpler option for some, compared to supplying a custom testEnvironment with an async setup method.

@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 10, 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

5 participants