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(jest-runtime): expose isEnvironmentTornDown variable #13741

Merged
merged 11 commits into from
Jan 15, 2023

Conversation

jomendez
Copy link
Contributor

@jomendez jomendez commented Jan 7, 2023

This PR adds a new feature to the Jest runtime package that exposes the isEnvironmentTornDown method to check if the Jest environment has been torn down programmatically. The isEnvironmentTornDown function returns a boolean that is set to true when the environment is torn down and false otherwise.

The commit also adds documentation for the isTornDown variable to the Jest runtime module.

Closes #13640

Summary

The motivation for exposing the isTornDown variable in the Jest runtime package is to provide a way for tests to check if the Jest environment has been torn down programmatically.
issue #13640 requesting this feature.

Test plan

Test Objective

The objective of this test is to verify that the isTornDown variable is correctly exposed in the Jest runtime package and that it can be used to check if the Jest environment has been torn down programmatically.

Test Steps

  1. Clone the Jest repository and make sure that the isEnvironmentTornDown feature has been implemented and is ready for testing.
  2. Create a new test file that imports the jest global object and uses the isEnvironmentTornDown method to check if the Jest environment has been torn down.
  3. Run the test file using the jest command.
  4. Verify that the test file runs successfully and that the isTornDown variable is correctly set to false when the Jest environment is not torn down.
  5. Modify the test file to tear down the Jest environment after the test has run.
  6. Run the test file again using the jest command.
  7. Verify that the test file runs successfully and that the isTornDown variable is correctly set to true when the Jest environment has been torn down.
  8. Modify the test file to check the isEnvironmentTornDown method in a loop that advances the fake timers by a specified amount of time.
  9. Run the test file again using the jest command and verify that the test file stops executing when the Jest environment is torn down.
  10. Modify the test file to check the isEnvironmentTornDown method in a loop that does a lot of work and can time out.
  11. Run the test file with a long timeout value (e.g. --timeout=10000) and verify that the test file stops executing when the Jest environment is torn down or the test times out.

Test Expected Results

  • The test file should run successfully and the isTornDown variable should be correctly set to false when the Jest environment is not torn down.
  • The test file should run successfully and the isTornDown variable should be correctly set to true when the Jest environment is torn down.
  • The test file should stop executing when the Jest environment is torn down or the test times out.

pepe added 5 commits December 27, 2022 19:52
This commit adds a new feature to the Jest runtime package that exposes
the `isTornDown` variable as a way to check if the Jest environment has
been torn down programmatically. The `isTornDown` variable is a
read-only boolean that is set to `true` when the environment is torn
down and `false` otherwise.

The commit also adds documentation for the `isTornDown` variable to the
Jest runtime module.

Closes jestjs#13640
This commit adds a new feature to the Jest runtime package that exposes
the `isTornDown` variable as a way to check if the Jest environment has
been torn down programmatically. The `isTornDown` variable is a
read-only boolean that is set to `true` when the environment is torn
down and `false` otherwise.

The commit also adds documentation for the `isTornDown` variable to the
Jest runtime module.

Closes jestjs#13640
…/jest into 13640-expose-isTornDown

# Conflicts:
#	packages/jest-environment/src/index.ts
…/jest into 13640-expose-isTornDown

# Conflicts:
#	packages/jest-environment/src/index.ts
…vironmentTornDown variable as a way to check if the Jest environment has been torndown
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.

Can you update the docs (https://github.com/facebook/jest/blob/main/docs/JestObjectAPI.md) and add a unit test?

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@mrazauskas mrazauskas left a comment

Choose a reason for hiding this comment

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

Just for completeness, could you add a type test here:

https://github.com/facebook/jest/blob/d2420aaf42055097dfe1e6a54bf3701214b06402/packages/jest-types/__typetests__/jest.test.ts#L577-L589

To run these, build the library and run yarn test-types.

packages/jest-environment/src/index.ts Outdated Show resolved Hide resolved
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.

thanks!

@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 Feb 15, 2023
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.

[Feature]: expose isTornDown readonly property
4 participants