feat(platform-server): provide a DOM implementation on the server

Fixes #14638

Uses Domino - https://github.com/fgnass/domino and removes dependency on
Parse5.

The DOCUMENT and nativeElement were never typed earlier and were
different on the browser(DOM nodes) and the server(Parse5 nodes). With
this change, platform-server also exposes a DOCUMENT and nativeElement
that is closer to the client. If you were relying on nativeElement on
the server, you would have to change your code to use the DOM API now
instead of Parse5 AST API.

Removes the need to add services for each and every Document
manipulation like Title/Meta etc.

This does *not* provide a global variable 'document' or 'window' on the
server. You still have to inject DOCUMENT to get the document backing
the current platform server instance.
This commit is contained in:
Vikram Subramanian
2017-08-08 02:17:40 -07:00
committed by Jason Aden
parent 30d53a8942
commit 2f2d5f35bd
21 changed files with 280 additions and 914 deletions

View File

@ -84,8 +84,8 @@ describe('template codegen output', () => {
it('should support i18n for content tags', () => {
const containerElement = createComponent(BasicComp).nativeElement;
const pElement = containerElement.children.find((c: any) => c.name == 'p');
const pText = pElement.children.map((c: any) => c.data).join('').trim();
const pElement = containerElement.querySelector('p');
const pText = pElement.textContent;
expect(pText).toBe('tervetuloa');
});

View File

@ -49,7 +49,7 @@ describe('NgModule', () => {
// https://github.com/angular/angular/issues/15221
const fixture = createComponent(ComponentUsingFlatModule);
const bundleComp = fixture.nativeElement.children;
expect(bundleComp[0].children[0].children[0].data).toEqual('flat module component');
expect(bundleComp[0].children[0].textContent).toEqual('flat module component');
});
});
@ -58,8 +58,8 @@ describe('NgModule', () => {
it('should support third party entryComponents components', () => {
const fixture = createComponent(ComponentUsingThirdParty);
const thirdPComps = fixture.nativeElement.children;
expect(thirdPComps[0].children[0].children[0].data).toEqual('3rdP-component');
expect(thirdPComps[1].children[0].children[0].data).toEqual(`other-3rdP-component
expect(thirdPComps[0].children[0].textContent).toEqual('3rdP-component');
expect(thirdPComps[1].children[0].textContent).toEqual(`other-3rdP-component
multi-lines`);
});