From fe4c73b68536188fa6c89a35e60504bd7e7515df Mon Sep 17 00:00:00 2001 From: Ahn <27772165+ahnpnl@users.noreply.github.com> Date: Sun, 11 Sep 2022 17:07:05 +0200 Subject: [PATCH] feat: remove `destroyAfterEach` and `teardown` options (#1768) BREAKING CHANGE `destroyAfterEach` and `teardown` are no longer available to use, please use `testEnvironmentOptions` instead. --- setup-jest.js | 32 +------------ setup-jest.mjs | 32 +------------ src/config/setup-jest.spec.ts | 90 ----------------------------------- src/global.d.ts | 4 +- 4 files changed, 3 insertions(+), 155 deletions(-) diff --git a/setup-jest.js b/setup-jest.js index 891a70de5f..fe9ba09569 100644 --- a/setup-jest.js +++ b/setup-jest.js @@ -5,36 +5,6 @@ const { platformBrowserDynamicTesting, } = require('@angular/platform-browser-dynamic/testing'); -let testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null); - -const configuredDestroyAfterEach = globalThis.ngJest?.destroyAfterEach; -if (configuredDestroyAfterEach) { - console.warn( - 'Passing destroyAfterEach for configuring the test environment has been deprecated.' + - ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + - ' see https://angular.io/api/core/testing/TestEnvironmentOptions' - ); - - testEnvironmentOptions = { - ...testEnvironmentOptions, - teardown: { - destroyAfterEach: true, - }, - }; -} - -const configuredTeardown = globalThis.ngJest?.teardown; -if (configuredTeardown) { - console.warn( - 'Passing teardown for configuring the test environment has been deprecated.' + - ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + - ' see https://angular.io/api/core/testing/TestEnvironmentOptions' - ); - - testEnvironmentOptions = { - ...testEnvironmentOptions, - teardown: configuredTeardown, - }; -} +const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null); getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), testEnvironmentOptions); diff --git a/setup-jest.mjs b/setup-jest.mjs index f80414848e..7f7e451745 100644 --- a/setup-jest.mjs +++ b/setup-jest.mjs @@ -2,36 +2,6 @@ import 'zone.js/fesm2015/zone-testing-bundle.min.js'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; -let testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null); - -const configuredDestroyAfterEach = globalThis.ngJest?.destroyAfterEach; -if (configuredDestroyAfterEach) { - console.warn( - 'Passing destroyAfterEach for configuring the test environment has been deprecated.' + - ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + - ' see https://angular.io/api/core/testing/TestEnvironmentOptions', - ); - - testEnvironmentOptions = { - ...testEnvironmentOptions, - teardown: { - destroyAfterEach: true, - }, - }; -} - -const configuredTeardown = globalThis.ngJest?.teardown; -if (configuredTeardown) { - console.warn( - 'Passing teardown for configuring the test environment has been deprecated.' + - ' Please pass a `testEnvironmentOptions` object with TestEnvironmentOptions interface instead,' + - ' see https://angular.io/api/core/testing/TestEnvironmentOptions', - ); - - testEnvironmentOptions = { - ...testEnvironmentOptions, - teardown: configuredTeardown, - }; -} +const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null); getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), testEnvironmentOptions); diff --git a/src/config/setup-jest.spec.ts b/src/config/setup-jest.spec.ts index e7d77d1260..d8a04cc0b9 100644 --- a/src/config/setup-jest.spec.ts +++ b/src/config/setup-jest.spec.ts @@ -52,51 +52,6 @@ describe('setup-jest', () => { }); describe('for CJS setup-jest, test environment initialization', () => { - test('should call getTestBed() and initTestEnvironment() with the ModuleTeardownOptions object passed to ngJest', async () => { - const spyConsoleWarn = (console.warn = jest.fn()); - globalThis.ngJest = { - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, - }; - await import('../../setup-jest'); - - expect(mockUmdZoneJs).toHaveBeenCalled(); - expect(spyConsoleWarn).toHaveBeenCalled(); - expect(spyConsoleWarn.mock.calls[0][0]).toMatchInlineSnapshot( - `"Passing teardown for configuring the test environment has been deprecated. Please pass a \`testEnvironmentOptions\` object with TestEnvironmentOptions interface instead, see https://angular.io/api/core/testing/TestEnvironmentOptions"`, - ); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, - }); - }); - - test('should call getTestBed() and initTestEnvironment() with the destroyAfterEach passed to ngJest', async () => { - const spyConsoleWarn = (console.warn = jest.fn()); - globalThis.ngJest = { - destroyAfterEach: true, - }; - - await import('../../setup-jest'); - - expect(mockUmdZoneJs).toHaveBeenCalled(); - expect(spyConsoleWarn).toHaveBeenCalled(); - expect(spyConsoleWarn.mock.calls[0][0]).toMatchInlineSnapshot( - `"Passing destroyAfterEach for configuring the test environment has been deprecated. Please pass a \`testEnvironmentOptions\` object with TestEnvironmentOptions interface instead, see https://angular.io/api/core/testing/TestEnvironmentOptions"`, - ); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: true, - }, - }); - }); - test('should call getTestBed() and initTestEnvironment() with the testEnvironmentOptions passed to ngJest', async () => { globalThis.ngJest = { testEnvironmentOptions: { @@ -125,51 +80,6 @@ describe('setup-jest', () => { }); describe('for ESM setup-jest, test environment initialization', () => { - test('should call getTestBed() and initTestEnvironment() with the ModuleTeardownOptions object passed to ngJest', async () => { - const spyConsoleWarn = (console.warn = jest.fn()); - globalThis.ngJest = { - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, - }; - await import('../../setup-jest.mjs'); - - expect(mockEsmZoneJs).toHaveBeenCalled(); - expect(spyConsoleWarn).toHaveBeenCalled(); - expect(spyConsoleWarn.mock.calls[0][0]).toMatchInlineSnapshot( - `"Passing teardown for configuring the test environment has been deprecated. Please pass a \`testEnvironmentOptions\` object with TestEnvironmentOptions interface instead, see https://angular.io/api/core/testing/TestEnvironmentOptions"`, - ); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: false, - rethrowErrors: true, - }, - }); - }); - - test('should call getTestBed() and initTestEnvironment() with the destroyAfterEach passed to ngJest', async () => { - const spyConsoleWarn = (console.warn = jest.fn()); - globalThis.ngJest = { - destroyAfterEach: true, - }; - - await import('../../setup-jest.mjs'); - - expect(mockEsmZoneJs).toHaveBeenCalled(); - expect(spyConsoleWarn).toHaveBeenCalled(); - expect(spyConsoleWarn.mock.calls[0][0]).toMatchInlineSnapshot( - `"Passing destroyAfterEach for configuring the test environment has been deprecated. Please pass a \`testEnvironmentOptions\` object with TestEnvironmentOptions interface instead, see https://angular.io/api/core/testing/TestEnvironmentOptions"`, - ); - assertOnInitTestEnv(); - expect(mockInitTestEnvironment.mock.calls[0][2]).toEqual({ - teardown: { - destroyAfterEach: true, - }, - }); - }); - test('should call getTestBed() and initTestEnvironment() with the testEnvironmentOptions passed to ngJest', async () => { globalThis.ngJest = { testEnvironmentOptions: { diff --git a/src/global.d.ts b/src/global.d.ts index f85cbbdb11..efe541f1a1 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,14 +1,12 @@ /* eslint-disable */ -import type { ModuleTeardownOptions, TestEnvironmentOptions } from '@angular/core/testing'; +import type { TestEnvironmentOptions } from '@angular/core/testing'; declare global { var ngJest: | { skipNgcc?: boolean; tsconfig?: string; - destroyAfterEach?: boolean; - teardown?: ModuleTeardownOptions; testEnvironmentOptions?: TestEnvironmentOptions; } | undefined;