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

Why was context removed in a point release? #2468

Closed
randycoulman opened this issue Dec 29, 2016 · 5 comments
Closed

Why was context removed in a point release? #2468

randycoulman opened this issue Dec 29, 2016 · 5 comments

Comments

@randycoulman
Copy link

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

Question/Feature

What is the current behavior?

I have a test suite that was working fine with Jest 18.0. When I upgraded to Jest 18.1, many of my tests started failing with the message, "ReferenceError: context is not defined".

It appears that context was removed as a synonym of describe in #2384, but no reasoning was given there, other than that it was "unused".

It seems like such a breaking change should not have been introduced in a point release.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?

My understanding was that context was provided as an alias for describe to make it easier to port tests from other frameworks to Jest. Certainly, this is the case for us, as we've been migrating several projects from Mocha to Jest recently.

In many situations, I find context to communicate my intentions better than describe, so I really like having the alias.

I would like to see the context alias restored and documented as part of Jest's API. To me, it is similar to having it and test as aliases of each other.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

Jest 18.1.0
Yarn 0.18.1
Node 6.9.2
OS/X 10.11.6

@cpojer
Copy link
Member

cpojer commented Dec 30, 2016

Context was controversial when it was added in #1632. We are currently rewriting the documentation of Jest and were analyzing the globals we add and realized context was almost entirely unused so we decided to remove this alias again. If you'd like to bring it back, you can do global.context = describe in a setupTestFrameworkScriptFile setting.

As to why this happened in a minor, here is what happened:

  • We made a ton of changes on master.
  • Right before Christmas, node 7.3 came out which has some buggy behavior which broke a ton of timer and console related things in Jest.
  • I was happily on a vacation and noticed that everything now sucks for our users so I decided to spend some time fixing it.
  • I tagged 18.1 because I didn't think the current amount of changes warranted a major release.
  • I did not tag 18.0.1 from an 18.x branch because this project doesn't have the resources to support branches like that. If you'd like to help out with release management on Jest, please let me know – I'd love to have your support!

@cpojer cpojer closed this as completed Dec 30, 2016
@randycoulman
Copy link
Author

@cpojer Thanks for the response. First, let me apologize for the tone of my original issue. I didn't spend enough time on it, and it came across sounding much harsher than I intended. I'm also sorry that you had to give up some vacation time to deal with an issue caused by someone else's change. I really appreciate the work you all have done on this project. It's because of that work that I'm even looking at Jest as an option.

I had thought about the global.context = describe solution, but I've already run across two tools this week that don't support context: globals and eslint-plugin-jest. That's why I was hoping for context to become a documented feature.

That said, I understand your reasoning for dropping it, though I disagree. And I understand the unfortunate circumstances that resulted in that happening on a point release. I'm not a big fan of multiple release tracks, so I wouldn't suggest you make your process more complicated than it is.

Again, thanks everyone for your work on the project!

@cpojer
Copy link
Member

cpojer commented Dec 30, 2016

Thanks for your response. ❤️

@wickkidd
Copy link

wickkidd commented Aug 1, 2019

@cpojer re: global.context = describe to bring context back...

I've done this in several node projects, however, for the life of me I can't get it to work with vscode in a project where the test files are typescript (using ts-jest). The tests run fine if I add a declaration file and wire it up properly for use in tsconfig's types and typeRoots properties, but vscode's intellisense underlines the instances of context with a ts2304 error.

The only way I've been able to get this to go away is to create a ts file (which must be open in the editor at all times) that is added to setupFilesAfterEnv with a /// <reference path="path/to/my/index.d.ts" /> (index.d.ts is where I declare var context: jest.Describe). The moment I close the file with the /// reference, vscode can't find the name "context" anymore.

Thanks in advance.

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

3 participants