| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:44:01 -07:00
										 |  |  | import {Component, NgModule, destroyPlatform} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-07-11 16:04:32 -07:00
										 |  |  | import {async} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  | import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | 
					
						
							| 
									
										
										
										
											2016-08-15 13:44:01 -07:00
										 |  |  | import {ServerModule, platformDynamicServer} from '@angular/platform-server'; | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | function writeBody(html: string): any { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |   const dom = getDOM(); | 
					
						
							|  |  |  |   const doc = dom.defaultDoc(); | 
					
						
							|  |  |  |   const body = dom.querySelector(doc, 'body'); | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  |   dom.setInnerHTML(body, html); | 
					
						
							|  |  |  |   return body; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:44:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'app', template: `Works!`}) | 
					
						
							|  |  |  | class MyServerApp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  | @NgModule({declarations: [MyServerApp], imports: [ServerModule], bootstrap: [MyServerApp]}) | 
					
						
							| 
									
										
										
										
											2016-08-15 13:44:01 -07:00
										 |  |  | class ExampleModule { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   if (getDOM().supportsDOMEvents()) return;  // NODE only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('platform-server integration', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-12 14:15:37 -07:00
										 |  |  |     beforeEach(() => destroyPlatform()); | 
					
						
							|  |  |  |     afterEach(() => destroyPlatform()); | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should bootstrap', async(() => { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |          const body = writeBody('<app></app>'); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:44:01 -07:00
										 |  |  |          platformDynamicServer().bootstrapModule(ExampleModule).then(() => { | 
					
						
							|  |  |  |            expect(getDOM().getText(body)).toEqual('Works!'); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2016-06-14 19:49:25 -07:00
										 |  |  |        })); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |