mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
build: Run browsers tests without platform-browser-dynamic (#60937)
Use the regular `platform-browser` providers instead. PR Close #60937
This commit is contained in:
parent
b250bb0a74
commit
b896ca8ed5
7 changed files with 49 additions and 48 deletions
|
|
@ -17,12 +17,9 @@ import {DOCUMENT} from '@angular/common';
|
|||
import {Component, NgZone, RendererFactory2, ViewChild} from '@angular/core';
|
||||
import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing';
|
||||
import {ɵDomRendererFactory2 as DomRendererFactory2} from '@angular/platform-browser';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting,
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
||||
import {ɵAsyncAnimationRendererFactory as AsyncAnimationRendererFactory} from '@angular/platform-browser/animations/async';
|
||||
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
|
||||
|
||||
describe('BrowserAnimationBuilder', () => {
|
||||
if (isNode) {
|
||||
|
|
@ -236,7 +233,7 @@ describe('BrowserAnimationBuilder', () => {
|
|||
// We need to reset the test environment because
|
||||
// browser_tests.init.ts inits the environment with the NoopAnimationsModule
|
||||
TestBed.resetTestEnvironment();
|
||||
TestBed.initTestEnvironment([BrowserDynamicTestingModule], platformBrowserDynamicTesting());
|
||||
TestBed.initTestEnvironment([BrowserTestingModule], platformBrowserTesting());
|
||||
});
|
||||
|
||||
it('should throw an error when injecting AnimationBuilder without animation providers set', () => {
|
||||
|
|
@ -249,8 +246,8 @@ describe('BrowserAnimationBuilder', () => {
|
|||
// We're reset the test environment to their default values, cf browser_tests.init.ts
|
||||
TestBed.resetTestEnvironment();
|
||||
TestBed.initTestEnvironment(
|
||||
[BrowserDynamicTestingModule, NoopAnimationsModule],
|
||||
platformBrowserDynamicTesting(),
|
||||
[BrowserTestingModule, NoopAnimationsModule],
|
||||
platformBrowserTesting(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ ts_library(
|
|||
"//packages/core/testing",
|
||||
"//packages/localize/init",
|
||||
"//packages/platform-browser",
|
||||
"//packages/platform-browser-dynamic",
|
||||
"//packages/platform-browser-dynamic/testing",
|
||||
"//packages/platform-browser/animations",
|
||||
"//packages/platform-browser/testing",
|
||||
"//packages/platform-server",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import {
|
|||
Compiler,
|
||||
CompilerFactory,
|
||||
Component,
|
||||
effect,
|
||||
EnvironmentInjector,
|
||||
InjectionToken,
|
||||
Injector,
|
||||
|
|
@ -23,7 +22,6 @@ import {
|
|||
NgModule,
|
||||
NgZone,
|
||||
PlatformRef,
|
||||
ProviderToken,
|
||||
provideZoneChangeDetection,
|
||||
RendererFactory2,
|
||||
TemplateRef,
|
||||
|
|
@ -48,6 +46,7 @@ import {ApplicationRef} from '../src/application/application_ref';
|
|||
import {NoopNgZone} from '../src/zone/ng_zone';
|
||||
import {ComponentFixtureNoNgZone, inject, TestBed, waitForAsync, withModule} from '../testing';
|
||||
import {take} from 'rxjs/operators';
|
||||
import {compileNgModuleFactory} from '../src/application/application_ngmodule_factory_compiler';
|
||||
|
||||
let serverPlatformModule: Promise<Type<ServerModule>> | null = null;
|
||||
if (isNode) {
|
||||
|
|
@ -677,30 +676,27 @@ describe('bootstrap', () => {
|
|||
initializerDone = true;
|
||||
}, 1);
|
||||
|
||||
const compilerFactory: CompilerFactory = defaultPlatform.injector.get(CompilerFactory, null)!;
|
||||
const moduleFactory = compilerFactory
|
||||
.createCompiler()
|
||||
.compileModuleSync(
|
||||
await createModule([{provide: APP_INITIALIZER, useValue: () => promise, multi: true}]),
|
||||
);
|
||||
const moduleType = await createModule([
|
||||
{provide: APP_INITIALIZER, useValue: () => promise, multi: true},
|
||||
]);
|
||||
const moduleFactory = await compileNgModuleFactory(defaultPlatform.injector, {}, moduleType);
|
||||
|
||||
defaultPlatform.bootstrapModuleFactory(moduleFactory).then((_) => {
|
||||
expect(initializerDone).toBe(true);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should rethrow sync errors even if the exceptionHandler is not rethrowing', waitForAsync(async () => {
|
||||
const compilerFactory: CompilerFactory = defaultPlatform.injector.get(CompilerFactory, null)!;
|
||||
const moduleFactory = compilerFactory.createCompiler().compileModuleSync(
|
||||
await createModule([
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useValue: () => {
|
||||
throw 'Test';
|
||||
},
|
||||
multi: true,
|
||||
const moduleType = await createModule([
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useValue: () => {
|
||||
throw 'Test';
|
||||
},
|
||||
]),
|
||||
);
|
||||
multi: true,
|
||||
},
|
||||
]);
|
||||
const moduleFactory = await compileNgModuleFactory(defaultPlatform.injector, {}, moduleType);
|
||||
expect(() => defaultPlatform.bootstrapModuleFactory(moduleFactory)).toThrow('Test');
|
||||
// Error rethrown will be seen by the exception handler since it's after
|
||||
// construction.
|
||||
|
|
@ -708,14 +704,10 @@ describe('bootstrap', () => {
|
|||
}));
|
||||
|
||||
it('should rethrow promise errors even if the exceptionHandler is not rethrowing', waitForAsync(async () => {
|
||||
const compilerFactory: CompilerFactory = defaultPlatform.injector.get(CompilerFactory, null)!;
|
||||
const moduleFactory = compilerFactory
|
||||
.createCompiler()
|
||||
.compileModuleSync(
|
||||
await createModule([
|
||||
{provide: APP_INITIALIZER, useValue: () => Promise.reject('Test'), multi: true},
|
||||
]),
|
||||
);
|
||||
const moduleType = await createModule([
|
||||
{provide: APP_INITIALIZER, useValue: () => Promise.reject('Test'), multi: true},
|
||||
]);
|
||||
const moduleFactory = await compileNgModuleFactory(defaultPlatform.injector, {}, moduleType);
|
||||
defaultPlatform.bootstrapModuleFactory(moduleFactory).then(
|
||||
() => expect(false).toBe(true),
|
||||
(e) => {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ import {
|
|||
ViewContainerRef,
|
||||
} from '../../src/core';
|
||||
import {fakeAsync, inject, TestBed, tick} from '../../testing';
|
||||
import {BrowserModule, By} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {BrowserModule, By, platformBrowser} from '@angular/platform-browser';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
describe('regressions', () => {
|
||||
|
|
@ -485,7 +484,7 @@ describe('regressions using bootstrap', () => {
|
|||
})
|
||||
class TestModule {}
|
||||
|
||||
platformBrowserDynamic()
|
||||
platformBrowser()
|
||||
.bootstrapModule(TestModule)
|
||||
.then((ref) => {
|
||||
NgZone.assertNotInAngularZone();
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@
|
|||
*/
|
||||
|
||||
import {ResourceLoader} from '@angular/compiler';
|
||||
import {Compiler, Component, NgModule} from '@angular/core';
|
||||
import {Compiler, Component, getPlatform, NgModule, PlatformRef} from '@angular/core';
|
||||
import {fakeAsync, inject, TestBed, tick, waitForAsync} from '@angular/core/testing';
|
||||
import {ResourceLoaderImpl} from '../src/resource_loader/resource_loader_impl';
|
||||
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '../testing';
|
||||
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
|
||||
|
||||
// Components for the tests.
|
||||
class FancyService {
|
||||
|
|
@ -54,6 +56,15 @@ if (isBrowser) {
|
|||
describe('using the test injector with the inject helper', () => {
|
||||
describe('setting up Providers', () => {
|
||||
beforeEach(() => {
|
||||
getPlatform()?.destroy();
|
||||
// We need to reset the test environment because
|
||||
// browser_tests.init.ts doesn't use platformBrowserDynamicTesting
|
||||
TestBed.resetTestEnvironment();
|
||||
TestBed.initTestEnvironment(
|
||||
[BrowserDynamicTestingModule],
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [{provide: FancyService, useValue: new FancyService()}],
|
||||
});
|
||||
|
|
@ -76,6 +87,14 @@ if (isBrowser) {
|
|||
expect(value).toEqual('async value');
|
||||
}),
|
||||
));
|
||||
|
||||
afterEach(() => {
|
||||
getPlatform()?.destroy();
|
||||
|
||||
// We're reset the test environment to their default values, cf browser_tests.init.ts
|
||||
TestBed.resetTestEnvironment();
|
||||
TestBed.initTestEnvironment([BrowserTestingModule], platformBrowserTesting());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ ts_library(
|
|||
":zone_base_setup_lib",
|
||||
"//packages/compiler",
|
||||
"//packages/core/testing",
|
||||
"//packages/platform-browser-dynamic/testing",
|
||||
"//packages/platform-browser/animations",
|
||||
"//packages/platform-browser/testing",
|
||||
"//packages/zone.js/lib",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,16 +11,10 @@ import './zone_base_setup';
|
|||
import '@angular/compiler'; // For JIT mode. Must be in front of any other @angular/* imports.
|
||||
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting,
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
|
||||
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
||||
|
||||
TestBed.initTestEnvironment(
|
||||
[BrowserDynamicTestingModule, NoopAnimationsModule],
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
TestBed.initTestEnvironment([BrowserTestingModule, NoopAnimationsModule], platformBrowserTesting());
|
||||
|
||||
(window as any).isNode = false;
|
||||
(window as any).isBrowser = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue