Skip to content

Commit 3490c18

Browse files
committed
test(@ngtools/webpack): add tests for webpack for platform-server
1 parent 1404a1b commit 3490c18

14 files changed

+247
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
<h1>hello world</h1>
3+
<a [routerLink]="['lazy']">lazy</a>
4+
<router-outlet></router-outlet>
5+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host {
2+
background-color: blue;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Component, ViewEncapsulation} from '@angular/core';
2+
import {MyInjectable} from './injectable';
3+
4+
5+
@Component({
6+
selector: 'app-root',
7+
templateUrl: './app.component.html',
8+
styleUrls: ['./app.component.scss'],
9+
encapsulation: ViewEncapsulation.None
10+
})
11+
export class AppComponent {
12+
constructor(public inj: MyInjectable) {
13+
console.log(inj);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NgModule, Component } from '@angular/core';
2+
import { ServerModule } from '@angular/platform-server';
3+
import { RouterModule } from '@angular/router';
4+
import { AppComponent } from './app.component';
5+
6+
@Component({
7+
selector: 'home-view',
8+
template: 'home!'
9+
})
10+
export class HomeView {}
11+
12+
13+
@NgModule({
14+
declarations: [
15+
AppComponent,
16+
HomeView
17+
],
18+
imports: [
19+
ServerModule,
20+
RouterModule.forRoot([
21+
{path: 'lazy', loadChildren: './lazy.module#LazyModule'},
22+
{path: '', component: HomeView}
23+
])
24+
],
25+
bootstrap: [AppComponent]
26+
})
27+
export class AppModule { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {NgModule, Component} from '@angular/core';
2+
import {RouterModule} from '@angular/router';
3+
4+
@Component({
5+
selector: 'feature-component',
6+
template: 'foo.html'
7+
})
8+
export class FeatureComponent {}
9+
10+
@NgModule({
11+
declarations: [
12+
FeatureComponent
13+
],
14+
imports: [
15+
RouterModule.forChild([
16+
{ path: '', component: FeatureComponent}
17+
])
18+
]
19+
})
20+
export class FeatureModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {NgModule, Component} from '@angular/core';
2+
import {RouterModule} from '@angular/router';
3+
import {HttpModule, Http} from '@angular/http';
4+
5+
@Component({
6+
selector: 'lazy-feature-comp',
7+
template: 'lazy feature!'
8+
})
9+
export class LazyFeatureComponent {}
10+
11+
@NgModule({
12+
imports: [
13+
RouterModule.forChild([
14+
{path: '', component: LazyFeatureComponent, pathMatch: 'full'},
15+
{path: 'feature', loadChildren: './feature.module#FeatureModule'}
16+
]),
17+
HttpModule
18+
],
19+
declarations: [LazyFeatureComponent]
20+
})
21+
export class LazyFeatureModule {
22+
constructor(http: Http) {}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Injectable, Inject, ViewContainerRef} from '@angular/core';
2+
import {DOCUMENT} from '@angular/platform-browser';
3+
4+
5+
@Injectable()
6+
export class MyInjectable {
7+
constructor(public viewContainer: ViewContainerRef, @Inject(DOCUMENT) public doc) {}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {NgModule, Component} from '@angular/core';
2+
import {RouterModule} from '@angular/router';
3+
import {HttpModule, Http} from '@angular/http';
4+
5+
@Component({
6+
selector: 'lazy-comp',
7+
template: 'lazy!'
8+
})
9+
export class LazyComponent {}
10+
11+
@NgModule({
12+
imports: [
13+
RouterModule.forChild([
14+
{path: '', component: LazyComponent, pathMatch: 'full'},
15+
{path: 'feature', loadChildren: './feature/feature.module#FeatureModule'},
16+
{path: 'lazy-feature', loadChildren: './feature/lazy-feature.module#LazyFeatureModule'}
17+
]),
18+
HttpModule
19+
],
20+
declarations: [LazyComponent]
21+
})
22+
export class LazyModule {
23+
constructor(http: Http) {}
24+
}
25+
26+
export class SecondModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'core-js/es7/reflect';
2+
import {platformDynamicServer} from '@angular/platform-dynamic-server';
3+
import {AppModule} from './app.module';
4+
5+
platformDynamicServer().bootstrapModule(AppModule);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
<title>Document</title>
5+
<base href="">
6+
</head>
7+
<body>
8+
<app-root></app-root>
9+
<script src="node_modules/zone.js/dist/zone.js"></script>
10+
<script src="dist/app.main.js"></script>
11+
</body>
12+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "test",
3+
"license": "MIT",
4+
"dependencies": {
5+
"@angular/common": "^4.0.0-rc.2",
6+
"@angular/compiler": "^4.0.0-rc.2",
7+
"@angular/compiler-cli": "^4.0.0-rc.2",
8+
"@angular/core": "^4.0.0-rc.2",
9+
"@angular/http": "^4.0.0-rc.2",
10+
"@angular/platform-browser": "^4.0.0-rc.2",
11+
"@angular/platform-browser-dynamic": "^4.0.0-rc.2",
12+
"@angular/platform-server": "^4.0.0-rc.2",
13+
"@angular/router": "^4.0.0-rc.2",
14+
"@ngtools/webpack": "0.0.0",
15+
"core-js": "^2.4.1",
16+
"rxjs": "^5.2.0",
17+
"zone.js": "^0.7.7"
18+
},
19+
"devDependencies": {
20+
"node-sass": "^4.5.0",
21+
"performance-now": "^0.2.0",
22+
"raw-loader": "^0.5.1",
23+
"sass-loader": "^6.0.3",
24+
"typescript": "^2.2.1",
25+
"webpack": "2.2.1"
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "",
4+
"module": "es2015",
5+
"moduleResolution": "node",
6+
"target": "es5",
7+
"noImplicitAny": false,
8+
"sourceMap": true,
9+
"mapRoot": "",
10+
"emitDecoratorMetadata": true,
11+
"experimentalDecorators": true,
12+
"lib": [
13+
"es2016",
14+
"dom"
15+
],
16+
"outDir": "lib",
17+
"skipLibCheck": true,
18+
"rootDir": "."
19+
},
20+
"angularCompilerOptions": {
21+
"genDir": "./app/ngfactory",
22+
"entryModule": "app/app.module#AppModule"
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const ngToolsWebpack = require('@ngtools/webpack');
2+
3+
module.exports = {
4+
resolve: {
5+
extensions: ['.ts', '.js']
6+
},
7+
target: 'web',
8+
entry: './app/main.ts',
9+
output: {
10+
path: './dist',
11+
publicPath: 'dist/',
12+
filename: 'app.main.js'
13+
},
14+
plugins: [
15+
new ngToolsWebpack.AotPlugin({
16+
tsConfigPath: './tsconfig.json'
17+
})
18+
],
19+
module: {
20+
loaders: [
21+
{ test: /\.scss$/, loaders: ['raw-loader', 'sass-loader'] },
22+
{ test: /\.css$/, loader: 'raw-loader' },
23+
{ test: /\.html$/, loader: 'raw-loader' },
24+
{ test: /\.ts$/, loader: '@ngtools/webpack' }
25+
]
26+
},
27+
devServer: {
28+
historyApiFallback: true
29+
}
30+
};
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {normalize} from 'path';
2+
import {createProjectFromAsset} from '../../../utils/assets';
3+
import {exec} from '../../../utils/process';
4+
import {expectFileSizeToBeUnder, expectFileToMatch} from '../../../utils/fs';
5+
6+
7+
export default function(skipCleaning: () => void) {
8+
return Promise.resolve()
9+
.then(() => createProjectFromAsset('webpack/test-server-app'))
10+
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
11+
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 420000))
12+
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 10000))
13+
.then(() => expectFileToMatch('dist/app.main.js',
14+
new RegExp('.bootstrapModuleFactory'))
15+
.then(() => expectFileToMatch('dist/app.main.js',
16+
new RegExp('MyInjectable.ctorParameters = .*'
17+
+ 'type: .*ViewContainerRef.*'
18+
+ 'type: undefined, decorators.*Inject.*args: .*DOCUMENT.*'))
19+
.then(() => expectFileToMatch('dist/app.main.js',
20+
new RegExp('AppComponent.ctorParameters = .*MyInjectable'))
21+
.then(() => skipCleaning());
22+
}

0 commit comments

Comments
 (0)