test(ivy): enable platform-server tests for ivy (#27102)
PR Close #27102
This commit is contained in:
parent
893c1735dd
commit
cf1ebdc079
|
@ -17,6 +17,7 @@ ts_library(
|
|||
"//packages/http/testing",
|
||||
"//packages/platform-browser",
|
||||
"//packages/platform-server",
|
||||
"//packages/private/testing",
|
||||
"@rxjs",
|
||||
"@rxjs//operators",
|
||||
],
|
||||
|
@ -26,7 +27,6 @@ jasmine_node_test(
|
|||
name = "test",
|
||||
bootstrap = ["angular/tools/testing/init_node_spec.js"],
|
||||
tags = [
|
||||
"fixme-ivy-aot",
|
||||
],
|
||||
deps = [
|
||||
":test_lib",
|
||||
|
|
|
@ -7,16 +7,17 @@
|
|||
*/
|
||||
|
||||
import {AnimationBuilder, animate, state, style, transition, trigger} from '@angular/animations';
|
||||
import {APP_BASE_HREF, PlatformLocation, isPlatformServer} from '@angular/common';
|
||||
import {PlatformLocation, isPlatformServer} from '@angular/common';
|
||||
import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
|
||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||
import {ApplicationRef, CompilerFactory, Component, HostListener, Inject, Injectable, Input, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, ViewEncapsulation, destroyPlatform, getPlatform} from '@angular/core';
|
||||
import {TestBed, async, inject} from '@angular/core/testing';
|
||||
import {async, inject} from '@angular/core/testing';
|
||||
import {Http, HttpModule, Response, ResponseOptions, XHRBackend} from '@angular/http';
|
||||
import {MockBackend, MockConnection} from '@angular/http/testing';
|
||||
import {BrowserModule, DOCUMENT, StateKey, Title, TransferState, makeStateKey} from '@angular/platform-browser';
|
||||
import {BrowserModule, DOCUMENT, Title, TransferState, makeStateKey} from '@angular/platform-browser';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {BEFORE_APP_SERIALIZED, INITIAL_CONFIG, PlatformState, ServerModule, ServerTransferStateModule, platformDynamicServer, renderModule, renderModuleFactory} from '@angular/platform-server';
|
||||
import {fixmeIvy} from '@angular/private/testing';
|
||||
import {Observable} from 'rxjs';
|
||||
import {first} from 'rxjs/operators';
|
||||
|
||||
|
@ -432,6 +433,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('no deduplication of imported modules') &&
|
||||
it('adds styles with ng-transition attribute', async(() => {
|
||||
const platform = platformDynamicServer([{
|
||||
provide: INITIAL_CONFIG,
|
||||
|
@ -538,6 +540,7 @@ class HiddenModule {
|
|||
});
|
||||
afterEach(() => { expect(called).toBe(true); });
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('using long form should work', async(() => {
|
||||
const platform =
|
||||
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: doc}}]);
|
||||
|
@ -549,12 +552,14 @@ class HiddenModule {
|
|||
.toPromise();
|
||||
})
|
||||
.then((b) => {
|
||||
expect(platform.injector.get(PlatformState).renderToString()).toBe(expectedOutput);
|
||||
expect(platform.injector.get(PlatformState).renderToString())
|
||||
.toBe(expectedOutput);
|
||||
platform.destroy();
|
||||
called = true;
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('using renderModule should work', async(() => {
|
||||
renderModule(AsyncServerModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(expectedOutput);
|
||||
|
@ -574,6 +579,7 @@ class HiddenModule {
|
|||
});
|
||||
})));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('works with SVG elements', async(() => {
|
||||
renderModule(SVGServerModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
|
@ -583,6 +589,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('works with animation', async(() => {
|
||||
renderModule(AnimationServerModule, {document: doc}).then(output => {
|
||||
expect(output).toContain('Works!');
|
||||
|
@ -603,6 +610,7 @@ class HiddenModule {
|
|||
}));
|
||||
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('sets a prefix for the _nghost and _ngcontent attributes', async(() => {
|
||||
renderModule(ExampleStylesModule, {document: doc}).then(output => {
|
||||
expect(output).toMatch(
|
||||
|
@ -611,6 +619,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should handle false values on attributes', async(() => {
|
||||
renderModule(FalseAttributesModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
|
@ -620,6 +629,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should handle element property "name"', async(() => {
|
||||
renderModule(NameModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
|
@ -629,6 +639,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should work with sanitizer to handle "innerHTML"', async(() => {
|
||||
// Clear out any global states. These should be set when platform-server
|
||||
// is initialized.
|
||||
|
@ -642,6 +653,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should handle element property "hidden"', async(() => {
|
||||
renderModule(HiddenModule, {document: doc}).then(output => {
|
||||
expect(output).toBe(
|
||||
|
@ -651,6 +663,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should call render hook', async(() => {
|
||||
renderModule(RenderHookModule, {document: doc}).then(output => {
|
||||
// title should be added by the render hook.
|
||||
|
@ -661,6 +674,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('should call multiple render hooks', async(() => {
|
||||
const consoleSpy = spyOn(console, 'warn');
|
||||
renderModule(MultiRenderHookModule, {document: doc}).then(output => {
|
||||
|
@ -682,6 +696,7 @@ class HiddenModule {
|
|||
expect(ref.injector.get(Http) instanceof Http).toBeTruthy();
|
||||
});
|
||||
}));
|
||||
|
||||
it('can make Http requests', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -702,6 +717,8 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('no deduplication of imported modules') &&
|
||||
it('requests are macrotasks', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -713,7 +730,8 @@ class HiddenModule {
|
|||
NgZone.assertInAngularZone();
|
||||
mock.connections.subscribe((mc: MockConnection) => {
|
||||
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
mc.mockRespond(new Response(new ResponseOptions({body: 'success!', status: 200})));
|
||||
mc.mockRespond(
|
||||
new Response(new ResponseOptions({body: 'success!', status: 200})));
|
||||
});
|
||||
http.get('http://localhost/testing').subscribe(resp => {
|
||||
expect(resp.text()).toBe('success!');
|
||||
|
@ -721,6 +739,7 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('works when HttpModule is included before ServerModule', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -740,6 +759,8 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('no deduplication of imported modules') &&
|
||||
it('works when HttpModule is included after ServerModule', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -751,7 +772,8 @@ class HiddenModule {
|
|||
NgZone.assertInAngularZone();
|
||||
mock.connections.subscribe((mc: MockConnection) => {
|
||||
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
mc.mockRespond(new Response(new ResponseOptions({body: 'success!', status: 200})));
|
||||
mc.mockRespond(
|
||||
new Response(new ResponseOptions({body: 'success!', status: 200})));
|
||||
});
|
||||
http.get('http://localhost/testing').subscribe(resp => {
|
||||
expect(resp.text()).toBe('success!');
|
||||
|
@ -759,6 +781,7 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('throws when given a relative URL', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -770,6 +793,7 @@ class HiddenModule {
|
|||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('HttpClient', () => {
|
||||
it('can inject HttpClient', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
|
@ -778,6 +802,7 @@ class HiddenModule {
|
|||
expect(ref.injector.get(HttpClient) instanceof HttpClient).toBeTruthy();
|
||||
});
|
||||
}));
|
||||
|
||||
it('can make HttpClient requests', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -793,6 +818,7 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('requests are macrotasks', async(() => {
|
||||
const platform = platformDynamicServer(
|
||||
[{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -809,6 +835,7 @@ class HiddenModule {
|
|||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('can use HttpInterceptor that injects HttpClient', () => {
|
||||
const platform =
|
||||
platformDynamicServer([{provide: INITIAL_CONFIG, useValue: {document: '<app></app>'}}]);
|
||||
|
@ -834,6 +861,7 @@ class HiddenModule {
|
|||
beforeEach(() => { called = false; });
|
||||
afterEach(() => { expect(called).toBe(true); });
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('adds transfer script tag when using renderModule', async(() => {
|
||||
renderModule(TransferStoreModule, {document: '<app></app>'}).then(output => {
|
||||
expect(output).toBe(defaultExpectedOutput);
|
||||
|
@ -853,6 +881,7 @@ class HiddenModule {
|
|||
});
|
||||
})));
|
||||
|
||||
fixmeIvy('to investigate') &&
|
||||
it('cannot break out of <script> tag in serialized output', async(() => {
|
||||
renderModule(EscapedTransferStoreModule, {
|
||||
document: '<esc-app></esc-app>'
|
||||
|
|
Loading…
Reference in New Issue