test(platform-server): add initial e2e tests for platform-server (#15061)

This commit is contained in:
vikerman
2017-03-14 17:11:39 -07:00
committed by Chuck Jazdzewski
parent 13686bb518
commit ff60c041f6
25 changed files with 413 additions and 16 deletions

View File

@ -0,0 +1,20 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule} from '@angular/core';
import {ServerModule} from '@angular/platform-server';
import {HelloWorldModule} from './app';
import {HelloWorldComponent} from './hello-world.component';
@NgModule({
bootstrap: [HelloWorldComponent],
imports: [HelloWorldModule, ServerModule],
})
export class HelloWorldServerModule {
}

View File

@ -0,0 +1,20 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {HelloWorldComponent} from './hello-world.component';
@NgModule({
declarations: [HelloWorldComponent],
bootstrap: [HelloWorldComponent],
imports: [BrowserModule.withServerTransition({appId: 'hlw'})],
})
export class HelloWorldModule {
}

View File

@ -0,0 +1,17 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import 'zone.js/dist/zone.js';
import {enableProdMode} from '@angular/core';
import {platformBrowser} from '@angular/platform-browser';
import {HelloWorldModuleNgFactory} from './app.ngfactory';
window['doBootstrap'] = function() {
platformBrowser().bootstrapModuleFactory(HelloWorldModuleNgFactory);
};

View File

@ -0,0 +1,24 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component} from '@angular/core';
@Component({
selector: 'hello-world-app',
template: `
<div>Hello {{ name }}!</div>
`,
styles: [`
div {
font-weight: bold;
}
`]
})
export class HelloWorldComponent {
name: string = 'world';
}

View File

@ -0,0 +1,10 @@
<html>
<head>
<meta charset="UTF-8">
<title>Hello World</title>
<script src="built/helloworld-bundle.js"></script>
</head>
<body>
<hello-world-app></hello-world-app>
</body>
</html>

View File

@ -0,0 +1,40 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:no-console */
require('zone.js/dist/zone-node.js');
import {enableProdMode, NgModuleFactory} from '@angular/core';
import {renderModuleFactory} from '@angular/platform-server';
import * as express from 'express';
import {HelloWorldServerModuleNgFactory} from './helloworld/app.server.ngfactory';
const helloworld = require('raw-loader!./helloworld/index.html');
const app = express();
function render<T>(moduleFactory: NgModuleFactory<T>, html: string) {
return (req, res) => {
renderModuleFactory(moduleFactory, {
document: html,
url: req.url,
}).then((response) => { res.send(response); });
};
}
enableProdMode();
// Client bundles will be statically served from the built/ directory.
app.use('/built', express.static('built'));
// Keep the browser logs free of errors.
app.get('/favicon.ico', (req, res) => { res.send(''); });
//-----------ADD YOUR SERVER SIDE RENDERED APP HERE ----------------------
app.get('/helloworld', render(HelloWorldServerModuleNgFactory, helloworld));
app.listen(9876, function() { console.log('Server listening on port 9876!'); });