Skip to content

Commit 57bfb78

Browse files
Fabian Wilesdavideast
authored andcommitted
feat(core): introduce universal app for testing (#1140)
1 parent db75c45 commit 57bfb78

15 files changed

+5240
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test": "karma start --single-run",
88
"test:watch": "concurrently \"npm run build:watch\" \"npm run delayed_karma\"",
99
"test:debug": "npm run build && karma start",
10+
"test:universal": "npm run build && cp -R dist/packages-dist test/universal-test/node_modules/angularfire2 && cd test/universal-test && npm run prerender",
1011
"delayed_karma": "sleep 10 && karma start",
1112
"build": "rm -rf dist && node tools/build.js",
1213
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"

test/universal-test/.angular-cli.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"project": {
4+
"name": "universal-test"
5+
},
6+
"apps": [
7+
{
8+
"platform": "server",
9+
"root": "src",
10+
"outDir": "dist-server",
11+
"index": "index.html",
12+
"main": "main.server.ts",
13+
"tsconfig": "tsconfig.server.json",
14+
"prefix": "app"
15+
}
16+
]
17+
}

test/universal-test/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist-server
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
testem.log
34+
/typings
35+
yarn-error.log
36+
37+
# e2e
38+
/e2e/*.js
39+
/e2e/*.map
40+
41+
# System Files
42+
.DS_Store
43+
Thumbs.db

test/universal-test/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "universal-test",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"prerender": "ng build --prod --output-hashing=false && node prerender"
7+
},
8+
"private": true,
9+
"dependencies": {
10+
"@angular/animations": "^4.2.4",
11+
"@angular/common": "^4.2.4",
12+
"@angular/compiler": "^4.2.4",
13+
"@angular/core": "^4.2.4",
14+
"@angular/forms": "^4.2.4",
15+
"@angular/http": "^4.2.4",
16+
"@angular/platform-browser": "^4.2.4",
17+
"@angular/platform-browser-dynamic": "^4.2.4",
18+
"@angular/router": "^4.2.4",
19+
"core-js": "^2.4.1",
20+
"rxjs": "^5.4.2",
21+
"zone.js": "^0.8.14"
22+
},
23+
"devDependencies": {
24+
"@angular/cli": "1.3.2",
25+
"@angular/compiler-cli": "^4.2.4",
26+
"@angular/language-service": "^4.2.4",
27+
"@angular/platform-server": "^4.3.6",
28+
"typescript": "~2.3.3"
29+
}
30+
}

test/universal-test/prerender.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require('zone.js/dist/zone-node');
2+
const { renderModuleFactory } = require('@angular/platform-server');
3+
const fs = require('fs');
4+
5+
const { AppServerModuleNgFactory } = require(`./dist-server/main.bundle`);
6+
const index = require('fs').readFileSync('./src/index.html', 'utf8');
7+
8+
let renderComplete = false;
9+
setTimeout(() => {
10+
if(!renderComplete){
11+
throw new Error('universal app took toolong to render, it probably didnt clsoe the connection in time');
12+
}
13+
}, 5000);
14+
console.log('starting bootstrap...');
15+
renderModuleFactory(AppServerModuleNgFactory, {
16+
document: index,
17+
url: '/'
18+
})
19+
.then(html => {
20+
console.log('bootstrap done');
21+
renderComplete = true;
22+
fs.writeFileSync('./dist-server/index.html', html)
23+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from '@angular/core';
2+
import { AngularFireDatabase } from 'angularfire2/database';
3+
@Component({
4+
selector: 'app-root',
5+
template: `
6+
<h1>
7+
Welcome to {{title}}!!
8+
</h1>
9+
`,
10+
styles: []
11+
})
12+
export class AppComponent {
13+
title = 'Universal Test'
14+
constructor(
15+
private afDb: AngularFireDatabase
16+
){
17+
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { AngularFireModule } from 'angularfire2';
4+
import { AngularFireDatabaseModule } from 'angularfire2/database';
5+
import { AppComponent } from './app.component';
6+
7+
@NgModule({
8+
imports: [
9+
BrowserModule.withServerTransition({appId: 'my-app'}),
10+
AngularFireDatabaseModule,
11+
AngularFireModule.initializeApp({
12+
apiKey: "AIzaSyDFbuKX0UeXje-PRAvwIymYo2jk-uGqMa4",
13+
authDomain: "test-bc800.firebaseapp.com",
14+
databaseURL: "https://test-bc800.firebaseio.com",
15+
storageBucket: ""
16+
}),
17+
],
18+
declarations: [ AppComponent ],
19+
bootstrap: [ AppComponent ]
20+
})
21+
22+
export class AppModule { }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {NgModule} from '@angular/core';
2+
import {ServerModule} from '@angular/platform-server';
3+
4+
import {AppModule} from './app.module';
5+
import {AppComponent} from './app.component';
6+
7+
@NgModule({
8+
imports: [
9+
AppModule,
10+
ServerModule,
11+
],
12+
bootstrap: [AppComponent],
13+
})
14+
export class AppServerModule {}

test/universal-test/src/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>UniversalTest</title>
6+
<base href="/">
7+
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
</head>
10+
<body>
11+
<app-root></app-root>
12+
</body>
13+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {AppServerModule} from './app/app.server.module';

0 commit comments

Comments
 (0)