From a3040363e58cc0f44bddf702db6afa23a309a818 Mon Sep 17 00:00:00 2001 From: ahnpnl Date: Fri, 15 Nov 2024 16:47:22 +0700 Subject: [PATCH] feat: deprecate `setup-jest.js` and `setup-jest.mjs` DEPRECATION Importing `setup-jest.js`/`setup-jest.mjs` directly is deprecated. The files will be removed in the future. Please use "setupZoneTestEnv" function instead. Example: For CJS ``` // setup-jest.ts import { setupZoneTestEnv } from 'jest-preset-angular/setup-env'; setupZoneTestEnv(); ``` For ESM ``` // setup-jest.ts import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/index.mjs'; setupZoneTestEnv(); ``` --- setup-jest.js | 10 ++++++++++ setup-jest.mjs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/setup-jest.js b/setup-jest.js index 684d8b7bf2..4528ff46e6 100644 --- a/setup-jest.js +++ b/setup-jest.js @@ -1,3 +1,13 @@ +console.warn(` + Importing "setup-jest.js" directly is deprecated. The file "setup-jest.js" will be removed in the future. + Please use "setupZoneTestEnv" function instead. Example: + + // setup-jest.ts + import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone'; + + setupZoneTestEnv(); +`); + require('zone.js'); require('zone.js/testing'); const { TextEncoder, TextDecoder } = require('util'); diff --git a/setup-jest.mjs b/setup-jest.mjs index 8ff1a7c2d0..19752ef617 100644 --- a/setup-jest.mjs +++ b/setup-jest.mjs @@ -1,8 +1,19 @@ +console.warn(` + Importing "setup-jest.mjs" directly is deprecated. The file "setup-jest.mjs" will be removed in the future. + Please use "setupZoneTestEnv" function instead. Example: + + // setup-jest.ts + import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone/index.mjs'; + + setupZoneTestEnv(); +`); + import 'zone.js'; import 'zone.js/testing'; +import { TextEncoder, TextDecoder } from 'util'; + import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; -import { TextEncoder, TextDecoder } from 'util'; if (typeof globalThis.TextEncoder === 'undefined') { globalThis.TextEncoder = TextEncoder;