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

BUG: if Promise doesn’t complete, remains waiting (instead of timeout) #31

Closed
akauppi opened this issue Jun 27, 2021 · 6 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@akauppi
Copy link
Owner

akauppi commented Jun 27, 2021

Steps:

Change this line to have a doc ID that doesn't get changed:

    await expect( waitForIt("projects/1/userInfo/abc_") ).resolves.toContainObject(william);
$ npm test

Expected:

  • test should fail
  • user should get back to command line prompt

Actual:

  • execution does not return to command line
@akauppi
Copy link
Owner Author

akauppi commented Jun 27, 2021

The problem is that there's no timeout in the Promise, and JavaScript promises cannot be cancelled from outside.

@akauppi akauppi changed the title BUG: remains waiting for a promise (instead of timeout) BUG: if Promise doesn’t complete, remains waiting (instead of timeout) Jul 7, 2021
@akauppi
Copy link
Owner Author

akauppi commented Jul 7, 2021

Suggestion for a work-around:

If we’re able to detect when the Jest environment has been torn down, make a setTimeout callback check that every 100ms or so, and cancel the Promise ”from within” if the environment is down.

This won’t allow us to change a timeout (in the reports) to success/fail, but it should be enough to let the execution pass (focus of the issue).

…aaand we can know the environment is down simply by making an �afterAll

@akauppi
Copy link
Owner Author

akauppi commented Jul 7, 2021

jestjs/jest#9685

@akauppi akauppi self-assigned this Jul 7, 2021
@akauppi
Copy link
Owner Author

akauppi commented Jul 7, 2021

Could bring eventually back, maybe as:

eventually.doc(docPath)

@akauppi akauppi added the enhancement New feature or request label Jul 7, 2021
@akauppi akauppi added this to the Next milestone Jul 7, 2021
@akauppi
Copy link
Owner Author

akauppi commented Jul 7, 2021

Did a small experiment; can indeed tap into the afterAll and have the execution return to OS. (however...)

The thing keeping Jest from returning the control is the Firebase listener; not an unresolved Promise (Jest seems fine with those).

A suitable solution can be done. Since this repo is about Firebase / Jest interaction, this might be as good a place as any to do it.

(ultimately, Firebase could be more Jest friendly?)

@akauppi
Copy link
Owner Author

akauppi commented Jul 7, 2021

Fixed in 05b1eb9, coming to next release.

The fix wraps .onSnapshot so that the programming API remains the normal for tests, but if there are unreleased listeners when Jest exits, those are released.

@akauppi akauppi closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant