File tree Expand file tree Collapse file tree 5 files changed +24
-0
lines changed
Expand file tree Collapse file tree 5 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 88- ` [jest-haste-map] ` ignore Sapling vcs directories (` .sl/ ` ) ([ #13674 ] ( https://github.com/facebook/jest/pull/13674 ) )
99- ` [jest-resolve] ` Support subpath imports ([ #13705 ] ( https://github.com/facebook/jest/pull/13705 ) , [ #13723 ] ( https://github.com/facebook/jest/pull/13723 ) )
1010- ` [jest-runtime] ` Add ` jest.isolateModulesAsync ` for scoped module initialization of asynchronous functions ([ #13680 ] ( https://github.com/facebook/jest/pull/13680 ) )
11+ - ` [jest-runtime] ` Add ` jest.isEnvironmentTornDown ` function ([ #13698 ] ( https://github.com/facebook/jest/pull/13698 ) )
1112- ` [jest-test-result] ` Added ` skipped ` and ` focused ` status to ` FormattedTestResult ` ([ #13700 ] ( https://github.com/facebook/jest/pull/13700 ) )
1213
1314### Fixes
Original file line number Diff line number Diff line change @@ -172,6 +172,15 @@ export interface Jest {
172172 * local module state doesn't conflict between tests.
173173 */
174174 isolateModules ( fn : ( ) => void ) : Jest ;
175+ /**
176+ * Returns `true` if test environment has been torn down.
177+ * @example
178+ * if (jest.isEnvironmentTornDown()) {
179+ * // The Jest environment has been torn down, so stop doing work
180+ * return;
181+ * }
182+ */
183+ isEnvironmentTornDown ( ) : boolean ;
175184 /**
176185 * `jest.isolateModulesAsync()` is the equivalent of `jest.isolateModules()`, but for
177186 * async functions to be wrapped. The caller is expected to `await` the completion of
Original file line number Diff line number Diff line change @@ -66,4 +66,14 @@ describe('Runtime', () => {
6666 expect ( mock2 ) . not . toHaveBeenCalled ( ) ;
6767 } ) ;
6868 } ) ;
69+
70+ describe ( 'jest.isEnvironmentTornDown()' , ( ) => {
71+ it ( 'should be set to true when the environment is torn down' , async ( ) => {
72+ const runtime = await createRuntime ( __filename ) ;
73+ const root = runtime . requireModule ( runtime . __mockRootPath ) ;
74+ expect ( root . jest . isEnvironmentTornDown ( ) ) . toBe ( false ) ;
75+ runtime . teardown ( ) ;
76+ expect ( root . jest . isEnvironmentTornDown ( ) ) . toBe ( true ) ;
77+ } ) ;
78+ } ) ;
6979} ) ;
Original file line number Diff line number Diff line change @@ -2237,6 +2237,7 @@ export default class Runtime {
22372237 return this . _globalConfig . seed ;
22382238 } ,
22392239 getTimerCount : ( ) => _getFakeTimers ( ) . getTimerCount ( ) ,
2240+ isEnvironmentTornDown : ( ) => this . isTornDown ,
22402241 isMockFunction : this . _moduleMocker . isMockFunction ,
22412242 isolateModules,
22422243 isolateModulesAsync : this . isolateModulesAsync ,
Original file line number Diff line number Diff line change @@ -587,3 +587,6 @@ expectError(jest.setTimeout());
587587
588588expectType < number > ( jest . getSeed ( ) ) ;
589589expectError ( jest . getSeed ( 123 ) ) ;
590+
591+ expectType < boolean > ( jest . isEnvironmentTornDown ( ) ) ;
592+ expectError ( jest . isEnvironmentTornDown ( 123 ) ) ;
You can’t perform that action at this time.
0 commit comments