Skip to content

feat(core): introduce universal app for testing #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "karma start --single-run",
"test:watch": "concurrently \"npm run build:watch\" \"npm run delayed_karma\"",
"test:debug": "npm run build && karma start",
"test:universal": "npm run build && cp -R dist/packages-dist test/universal-test/node_modules/angularfire2 && cd test/universal-test && npm run prerender",
"delayed_karma": "sleep 10 && karma start",
"build": "rm -rf dist && node tools/build.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
Expand Down
17 changes: 17 additions & 0 deletions test/universal-test/.angular-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "universal-test"
},
"apps": [
{
"platform": "server",
"root": "src",
"outDir": "dist-server",
"index": "index.html",
"main": "main.server.ts",
"tsconfig": "tsconfig.server.json",
"prefix": "app"
}
]
}
43 changes: 43 additions & 0 deletions test/universal-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist-server
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings
yarn-error.log

# e2e
/e2e/*.js
/e2e/*.map

# System Files
.DS_Store
Thumbs.db
30 changes: 30 additions & 0 deletions test/universal-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "universal-test",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"prerender": "ng build --prod --output-hashing=false && node prerender"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.3.2",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@angular/platform-server": "^4.3.6",
"typescript": "~2.3.3"
}
}
23 changes: 23 additions & 0 deletions test/universal-test/prerender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require('zone.js/dist/zone-node');
const { renderModuleFactory } = require('@angular/platform-server');
const fs = require('fs');

const { AppServerModuleNgFactory } = require(`./dist-server/main.bundle`);
const index = require('fs').readFileSync('./src/index.html', 'utf8');

let renderComplete = false;
setTimeout(() => {
if(!renderComplete){
throw new Error('universal app took toolong to render, it probably didnt clsoe the connection in time');
}
}, 5000);
console.log('starting bootstrap...');
renderModuleFactory(AppServerModuleNgFactory, {
document: index,
url: '/'
})
.then(html => {
console.log('bootstrap done');
renderComplete = true;
fs.writeFileSync('./dist-server/index.html', html)
});
19 changes: 19 additions & 0 deletions test/universal-test/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
@Component({
selector: 'app-root',
template: `
<h1>
Welcome to {{title}}!!
</h1>
`,
styles: []
})
export class AppComponent {
title = 'Universal Test'
constructor(
private afDb: AngularFireDatabase
){

}
}
22 changes: 22 additions & 0 deletions test/universal-test/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AppComponent } from './app.component';

@NgModule({
imports: [
BrowserModule.withServerTransition({appId: 'my-app'}),
AngularFireDatabaseModule,
AngularFireModule.initializeApp({
apiKey: "AIzaSyDFbuKX0UeXje-PRAvwIymYo2jk-uGqMa4",
authDomain: "test-bc800.firebaseapp.com",
databaseURL: "https://test-bc800.firebaseio.com",
storageBucket: ""
}),
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})

export class AppModule { }
14 changes: 14 additions & 0 deletions test/universal-test/src/app/app.server.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {NgModule} from '@angular/core';
import {ServerModule} from '@angular/platform-server';

import {AppModule} from './app.module';
import {AppComponent} from './app.component';

@NgModule({
imports: [
AppModule,
ServerModule,
],
bootstrap: [AppComponent],
})
export class AppServerModule {}
13 changes: 13 additions & 0 deletions test/universal-test/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>UniversalTest</title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
1 change: 1 addition & 0 deletions test/universal-test/src/main.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {AppServerModule} from './app/app.server.module';
72 changes: 72 additions & 0 deletions test/universal-test/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
*/

/***************************************************************************************************
* BROWSER POLYFILLS
*/

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.

/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/**
* Required to support Web Animations `@angular/animation`.
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.



/***************************************************************************************************
* Zone JS is required by Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.



/***************************************************************************************************
* APPLICATION IMPORTS
*/

/**
* Date, currency, decimal and percent pipes.
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
*/
// import 'intl'; // Run `npm install --save intl`.
/**
* Need to import at least one locale-data with intl.
*/
// import 'intl/locale-data/jsonp/en';
16 changes: 16 additions & 0 deletions test/universal-test/src/tsconfig.server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "commonjs",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}
19 changes: 19 additions & 0 deletions test/universal-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Loading