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

feat(globals): make test return values stricter #10512

Merged
merged 3 commits into from
Dec 5, 2020

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Sep 14, 2020

Summary

This tweaks the types you get when importing from @jest/globals to

  1. only allow promises or no return value
  2. disallow mixing a done callback with returning a promise

Code changes not in packages/jest-types/src/Global.ts (and the test) can land on master now. No rush, though

Test plan

Type tests added, so green CI

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth to note that this is TS only and doesn't affect runtime, so breaking only for TS users.

@@ -4,6 +4,8 @@

- `[jest-circus, jest-config, jest-runtime]` Add new `injectGlobals` config and CLI option to disable injecting global variables into the runtime ([#10484](https://github.com/facebook/jest/pull/10484))
- `[jest-each]` Fixes `.each` type to always be callable ([#10447](https://github.com/facebook/jest/pull/10447))
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
- `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
Copy link
Collaborator

@thymikee thymikee Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually affects jest-types only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just a types change, yeah. The global types that everybody uses today (including us) lives in DefinitelyTyped.

@SimenB
Copy link
Member Author

SimenB commented Sep 14, 2020

I think it's worth to note that this is TS only and doesn't affect runtime, so breaking only for TS users.

Yup. I wanna make Jest throw at runtime for these cases as well, FWIW. This PR is just types, tho. Could do both at same time? So the types reflect reality instead of the reality we want :)

@thymikee
Copy link
Collaborator

I don't have any preference as long as it lands with breaking changes in 27, so whatever is easier :)

@@ -216,25 +226,17 @@ export const callAsyncCircusFn = (
});
};

returnedValue = fn.call<
Copy link
Member Author

@SimenB SimenB Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@villasv does any of this look wrong to you? Asking due to your work on #10836

@SimenB SimenB merged commit 460306c into jestjs:master Dec 5, 2020
@SimenB SimenB deleted the type-tweaks branch December 5, 2020 14:58
@github-actions
Copy link

This pull request 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants