Skip to content

chore: remove dependency on @angular/platform-browser-dynamic #3079

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { platformBrowser } from '@angular/platform-browser';

import { demoProviders } from './demo';

platformBrowserDynamic([demoProviders]);
platformBrowser([demoProviders]);
4 changes: 2 additions & 2 deletions examples/example-app-v19/src/app/demo/demo-main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { platformBrowser } from '@angular/platform-browser';

import { demoProviders } from './demo';

platformBrowserDynamic([demoProviders]);
platformBrowser([demoProviders]);
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"peerDependencies": {
"@angular/compiler-cli": ">=15.0.0 <20.0.0",
"@angular/core": ">=15.0.0 <20.0.0",
"@angular/platform-browser-dynamic": ">=15.0.0 <20.0.0",
"jest": "^29.0.0",
"jsdom": ">=20.0.0",
"typescript": ">=4.8"
Expand All @@ -82,7 +81,6 @@
"@angular/forms": "^19.2.8",
"@angular/material": "^19.2.11",
"@angular/platform-browser": "^19.2.8",
"@angular/platform-browser-dynamic": "^19.2.8",
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@commitlint/cli": "^19.8.0",
Expand Down
17 changes: 5 additions & 12 deletions setup-env/zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
require('zone.js/testing');

const { getTestBed } = require('@angular/core/testing');
const {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} = require('@angular/platform-browser-dynamic/testing');
const { BrowserTestingModule, platformBrowserTesting } = require('@angular/platform-browser/testing');

const { polyfillEncoder, resolveTestEnvOptions } = require('../utils');

const setupZoneTestEnv = (options) => {
polyfillEncoder();
const testEnvironmentOptions = resolveTestEnvOptions(options);
polyfillEncoder();

Check failure on line 10 in setup-env/zone/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
const testEnvironmentOptions = resolveTestEnvOptions(options);

Check failure on line 11 in setup-env/zone/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);
getTestBed().initTestEnvironment([BrowserTestingModule], platformBrowserTesting(), testEnvironmentOptions);

Check failure on line 13 in setup-env/zone/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
};

module.exports = {
setupZoneTestEnv,
setupZoneTestEnv,

Check failure on line 17 in setup-env/zone/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
};
12 changes: 4 additions & 8 deletions setup-env/zone/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
import 'zone.js/testing';

import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';

import { polyfillEncoder, resolveTestEnvOptions } from '../utils';

const setupZoneTestEnv = (options) => {
polyfillEncoder();
const testEnvironmentOptions = resolveTestEnvOptions(options);
polyfillEncoder();

Check failure on line 10 in setup-env/zone/index.mjs

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
const testEnvironmentOptions = resolveTestEnvOptions(options);

Check failure on line 11 in setup-env/zone/index.mjs

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);
getTestBed().initTestEnvironment([BrowserTestingModule], platformBrowserTesting(), testEnvironmentOptions);

Check failure on line 13 in setup-env/zone/index.mjs

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
};

export { setupZoneTestEnv };
71 changes: 34 additions & 37 deletions setup-env/zoneless/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
const { provideExperimentalZonelessChangeDetection, NgModule, ErrorHandler } = require('@angular/core');
const { getTestBed } = require('@angular/core/testing');
const {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} = require('@angular/platform-browser-dynamic/testing');
const { BrowserTestingModule, platformBrowserTesting } = require('@angular/platform-browser/testing');

const { polyfillEncoder, resolveTestEnvOptions } = require('../utils');

const provideZonelessConfig = () => {
class TestModule {}
NgModule({
providers: [
provideExperimentalZonelessChangeDetection(),
{
provide: ErrorHandler,
useValue: {
handleError: (e) => {
throw e;
},
},
},
],
})(TestModule);

return TestModule;
class TestModule {}

Check failure on line 8 in setup-env/zoneless/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
NgModule({

Check failure on line 9 in setup-env/zoneless/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Insert `··`
providers: [

Check failure on line 10 in setup-env/zoneless/index.js

View workflow job for this annotation

GitHub Actions / code_standard_check / lint

Replace `····` with `········`
provideExperimentalZonelessChangeDetection(),
{
provide: ErrorHandler,
useValue: {
handleError: (e) => {
throw e;
},
},
},
],
})(TestModule);

return TestModule;
};

const setupZonelessTestEnv = (options) => {
polyfillEncoder();
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
const testEnvironmentOptions = resolveTestEnvOptions(options);

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule, provideZonelessConfig()],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);

return;
}

throw Error(
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
polyfillEncoder();
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
const testEnvironmentOptions = resolveTestEnvOptions(options);

getTestBed().initTestEnvironment(
[BrowserTestingModule, provideZonelessConfig()],
platformBrowserTesting(),
testEnvironmentOptions,
);

return;
}

throw Error(
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
);
};

module.exports = {
setupZonelessTestEnv,
setupZonelessTestEnv,
};
66 changes: 33 additions & 33 deletions setup-env/zoneless/index.mjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import { ErrorHandler, NgModule, provideExperimentalZonelessChangeDetection } from '@angular/core';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';

import { polyfillEncoder, resolveTestEnvOptions } from '../utils';

const provideZonelessConfig = () => {
class TestModule {}
NgModule({
providers: [
provideExperimentalZonelessChangeDetection(),
{
provide: ErrorHandler,
useValue: {
handleError: (e) => {
throw e;
},
},
},
],
})(TestModule);

return TestModule;
class TestModule {}
NgModule({
providers: [
provideExperimentalZonelessChangeDetection(),
{
provide: ErrorHandler,
useValue: {
handleError: (e) => {
throw e;
},
},
},
],
})(TestModule);

return TestModule;
};

const setupZonelessTestEnv = (options) => {
polyfillEncoder();
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
const testEnvironmentOptions = resolveTestEnvOptions(options);

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule, provideZonelessConfig()],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);

return;
}

throw Error(
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
polyfillEncoder();
if (typeof provideExperimentalZonelessChangeDetection !== 'undefined') {
const testEnvironmentOptions = resolveTestEnvOptions(options);

getTestBed().initTestEnvironment(
[BrowserTestingModule, provideZonelessConfig()],
platformBrowserTesting(),
testEnvironmentOptions,
);

return;
}

throw Error(
'Cannot find provideExperimentalZonelessChangeDetection() to setup zoneless testing environment. ' +
'Please use setupZoneTestEnv() from jest-preset-angular/setup-env/setup-zone-env.mjs instead.',
);
};

export { setupZonelessTestEnv };
15 changes: 4 additions & 11 deletions setup-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ require('zone.js/testing');
const { TextEncoder, TextDecoder } = require('util');

const { getTestBed } = require('@angular/core/testing');
const {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} = require('@angular/platform-browser-dynamic/testing');
const { BrowserTestingModule, platformBrowserTesting } = require('@angular/platform-browser/testing');

if (typeof globalThis.TextEncoder === 'undefined') {
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
}

const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null);

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);
getTestBed().initTestEnvironment([BrowserTestingModule], platformBrowserTesting(), testEnvironmentOptions);
12 changes: 4 additions & 8 deletions setup-jest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ 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 { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';

if (typeof globalThis.TextEncoder === 'undefined') {
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
}

const testEnvironmentOptions = globalThis.ngJest?.testEnvironmentOptions ?? Object.create(null);

getTestBed().initTestEnvironment(
[BrowserDynamicTestingModule],
platformBrowserDynamicTesting(),
testEnvironmentOptions,
);
getTestBed().initTestEnvironment([BrowserTestingModule], platformBrowserTesting(), testEnvironmentOptions);
Loading
Loading