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: support aliases for jest globals (e.g. context) #1129

Merged
merged 1 commit into from Jun 4, 2022

Conversation

G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented May 28, 2022

I'm a bit on the fence about this: it ended up being a pretty straightforward addition but I'm worried it's catering to a very small niche because:

  1. it requires you to set up the globaled aliases with a custom setupTestFrameworkScriptFile
  2. you can get this already by importing the function you want to alias from @jest/globals
    • in addition to being a requirement if you're using ESM (since no globals), I think it's straight up easier than 1 as devs will already know how to import but would need to readup on jest configuration to know how to do 1

@SimenB do you think this is worth landing?

Resolves #83

@G-Rath
Copy link
Collaborator Author

G-Rath commented May 29, 2022

hmmm having this could allow us to deprecate the additionalTestBlockFunctions option that we've got on a few tests, which should reduce the logic of our rules and maybe improve some other rules for people (e.g. #534) without us having to do anything; so that could be another reason to land it.

Copy link
Member

@SimenB SimenB 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 this seems reasonable 👍

@G-Rath G-Rath merged commit 02ec945 into main Jun 4, 2022
@G-Rath G-Rath deleted the support-global-aliases branch June 4, 2022 23:12
@G-Rath
Copy link
Collaborator Author

G-Rath commented Jun 4, 2022

@SimenB do you think it's worth us checking if we can remove some of our rule options in favor of this?

github-actions bot pushed a commit that referenced this pull request Jun 4, 2022
# [26.5.0](v26.4.7...v26.5.0) (2022-06-04)

### Features

* support aliases for jest globals (e.g. `context`) ([#1129](#1129)) ([02ec945](02ec945))
@github-actions
Copy link

github-actions bot commented Jun 4, 2022

🎉 This PR is included in version 26.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@G-Rath
Copy link
Collaborator Author

G-Rath commented Jun 4, 2022

double hmmm: actually if we made this support checking local declarations (just for aliases - jest native functions would still be expected to be either globals or imported from @jest/globals), I think it should allow all of our rules to be customisable when combined with overrides.

This'd definitely let us drop a few rule-specific options, and resolve e.g. #1033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Are you open to support context as describe alias?
2 participants