Skip to content

Commit

Permalink
test: re-enable platform-server test
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Mar 26, 2018
1 parent 8b4ec64 commit 6cf7181
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 90 deletions.
76 changes: 39 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#da7fe5e",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#da7fe5e",
"@angular-devkit/core": "angular/angular-devkit-core-builds#da7fe5e",
"@angular-devkit/schematics": "angular/angular-devkit-schematics-builds#da7fe5e",
"@schematics/angular": "angular/schematics-angular-builds#da7fe5e",
"@schematics/package-update": "angular/schematics-package-update-builds#da7fe5e",
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#bee027f",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#bee027f",
"@angular-devkit/core": "angular/angular-devkit-core-builds#bee027f",
"@angular-devkit/schematics": "angular/angular-devkit-schematics-builds#bee027f",
"@schematics/angular": "angular/schematics-angular-builds#bee027f",
"@schematics/package-update": "angular/schematics-package-update-builds#bee027f",
"ajv": "^6.1.1",
"chalk": "~2.2.0",
"common-tags": "^1.3.1",
Expand Down
12 changes: 6 additions & 6 deletions packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#da7fe5e",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#da7fe5e",
"@angular-devkit/core": "angular/angular-devkit-core-builds#da7fe5e",
"@angular-devkit/schematics": "angular/angular-devkit-schematics-builds#da7fe5e",
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#bee027f",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#bee027f",
"@angular-devkit/core": "angular/angular-devkit-core-builds#bee027f",
"@angular-devkit/schematics": "angular/angular-devkit-schematics-builds#bee027f",
"@ngtools/json-schema": "1.2.0",
"@schematics/angular": "angular/schematics-angular-builds#da7fe5e",
"@schematics/package-update": "angular/schematics-package-update-builds#da7fe5e",
"@schematics/angular": "angular/schematics-angular-builds#bee027f",
"@schematics/package-update": "angular/schematics-package-update-builds#bee027f",
"ajv": "^6.1.1",
"chalk": "~2.2.0",
"common-tags": "^1.3.1",
Expand Down
135 changes: 95 additions & 40 deletions tests/e2e/tests/build/platform-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,79 +31,134 @@ export default function () {
}

return Promise.resolve()
.then(() => updateJsonFile('angular.json', configJson => {
const app = configJson['apps'][0];
delete app['polyfills'];
delete app['styles'];
app['platform'] = 'server';
}))
.then(() => updateJsonFile('package.json', packageJson => {
const dependencies = packageJson['dependencies'];
dependencies['@angular/platform-server'] = platformServerVersion;
}))
.then(() => updateTsConfig(tsConfig => {
tsConfig.compilerOptions.types = ['node'];
tsConfig['angularCompilerOptions'] = {
entryModule: 'app/app.module#AppModule'
.then(() => updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect['server'] = {
builder: '@angular-devkit/build-webpack:server',
options: {
outputPath: 'dist/test-project-server',
main: 'projects/test-project/src/main.server.ts',
tsConfig: 'projects/test-project/tsconfig.server.json'
}
};
}))
.then(() => writeFile('./src/main.ts', 'export { AppModule } from \'./app/app.module\';'))
.then(() => prependToFile('./src/app/app.module.ts',
'import { ServerModule } from \'@angular/platform-server\';'))
.then(() => replaceInFile('./src/app/app.module.ts', /\[\s*BrowserModule/g,
`[BrowserModule.withServerTransition(\{ appId: 'app' \}), ServerModule`))
.then(() => writeFile('./projects/test-project/tsconfig.server.json', `
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../dist-server",
"baseUrl": "./",
"module": "commonjs",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"entryModule": "src/app/app.server.module#AppServerModule"
}
}
`))
.then(() => writeFile('./projects/test-project/src/main.server.ts', `
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
export { AppServerModule } from './app/app.server.module';
`))
.then(() => writeFile('./projects/test-project/src/app/app.server.module.ts', `
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ServerModule } from '@angular/platform-server';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
@NgModule({
imports: [
AppModule,
BrowserModule.withServerTransition(\{ appId: 'app' \}),
ServerModule,
],
bootstrap: [AppComponent],
})
export class AppServerModule {}
`))
.then(() => silentNpm('install'))
.then(() => ng('build', '--aot=false'))
// This part of the test requires a non-aot build, which isn't available anymore.
// .then(() => ng('run', 'test-project:server'))
// // files were created successfully
// .then(() => expectFileToMatch('dist/test-project-server/main.js',
// /exports.*AppServerModule/))
// .then(() => writeFile('./index.js', `
// require('zone.js/dist/zone-node');
// require('reflect-metadata');
// const fs = require('fs');
// const \{ AppServerModule \} = require('./dist/test-project-server/main');
// const \{ renderModule \} = require('@angular/platform-server');

// renderModule(AppServerModule, \{
// url: '/',
// document: '<app-root></app-root>'
// \}).then(html => \{
// fs.writeFileSync('dist/test-project-server/index.html', html);
// \});
// `))
// .then(() => exec(normalize('node'), 'index.js'))
// .then(() => expectFileToMatch('dist/test-project-server/index.html',
// new RegExp('<h2 _ngcontent-c0="">Here are some links to help you start: </h2>')))
.then(() => ng('run', 'test-project:server'))
// files were created successfully
.then(() => expectFileToMatch('dist/test-project/main.js',
/exports.*AppModule/))
.then(() => expectFileToMatch('dist/test-project-server/main.js',
/exports.*AppServerModuleNgFactory/))
.then(() => writeFile('./index.js', `
require('zone.js/dist/zone-node');
require('reflect-metadata');
const fs = require('fs');
const \{ AppModule \} = require('./dist/test-project/main');
const \{ renderModule \} = require('@angular/platform-server');
const \{ AppServerModuleNgFactory \} = require('./dist/test-project-server/main');
const \{ renderModuleFactory \} = require('@angular/platform-server');
renderModule(AppModule, \{
renderModuleFactory(AppServerModuleNgFactory, \{
url: '/',
document: '<app-root></app-root>'
\}).then(html => \{
fs.writeFileSync('dist/test-project/index.html', html);
fs.writeFileSync('dist/test-project-server/index.html', html);
\});
`))
.then(() => exec(normalize('node'), 'index.js'))
.then(() => expectFileToMatch('dist/test-project/index.html',
new RegExp('<h2 _ngcontent-c0="">Here are some links to help you start: </h2>')))
.then(() => ng('build', '--aot'))
// files were created successfully
.then(() => expectFileToMatch('dist/test-project/main.js',
/exports.*AppModuleNgFactory/))
.then(() => replaceInFile('./index.js', /AppModule/g, 'AppModuleNgFactory'))
.then(() => replaceInFile('./index.js', /renderModule/g, 'renderModuleFactory'))
.then(() => exec(normalize('node'), 'index.js'))
.then(() => expectFileToMatch('dist/test-project/index.html',
.then(() => expectFileToMatch('dist/test-project-server/index.html',
new RegExp('<h2 _ngcontent-c0="">Here are some links to help you start: </h2>')))
.then(() => expectFileToMatch('./dist/test-project/main.js',
.then(() => expectFileToMatch('./dist/test-project-server/main.js',
/require\(["']@angular\/[^"']*["']\)/))

// Check externals.
.then(() => prependToFile('./src/app/app.module.ts', `
.then(() => prependToFile('./projects/test-project/src/app/app.server.module.ts', `
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
`)
.then(() => appendToFile('./src/app/app.module.ts', `
.then(() => appendToFile('./projects/test-project/src/app/app.server.module.ts', `
import * as fs from 'fs';
import { renderModule } from '@angular/platform-server';
renderModule(AppModule, \{
url: '/',
document: '<app-root></app-root>'
\}).then(html => \{
fs.writeFileSync('dist/test-project/index.html', html);
fs.writeFileSync('dist/test-project-server/index.html', html);
\});
`)))
.then(() => ng('build', '--bundle-dependencies=all', '--aot=false'))
.then(() => expectToFail(() => expectFileToMatch('./dist/test-project/main.js',
/require\(["']@angular\/[^"']*["']\)/)))
.then(() => exec(normalize('node'), 'dist/test-project/main.js'));
// This part of the test requires a non-aot build, which isn't available anymore.
// .then(() => ng('run', 'test-project:server', '--bundle-dependencies=all'))
// .then(() => expectToFail(() => expectFileToMatch('./dist/test-project-server/main.js',
// /require\(["']@angular\/[^"']*["']\)/)))
// .then(() => exec(normalize('node'), 'dist/test-project-server/main.js'));
}
2 changes: 1 addition & 1 deletion tests/e2e_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const allTests = glob.sync(path.join(e2eRoot, testGlob), { nodir: true, ignore:
.filter(name => !name.endsWith('/build-app-shell-with-schematic.ts'))
.filter(name => !name.endsWith('/build-app-shell.ts'))
.filter(name => !name.endsWith('/bundle-budgets.ts'))
.filter(name => !name.endsWith('/platform-server.ts'))
.filter(name => !name.endsWith('/build/environment.ts'))
.filter(name => !name.endsWith('/service-worker.ts'))
.filter(name => !name.endsWith('/new-minimal.ts'))
// IS this test still valid? \/
Expand Down

0 comments on commit 6cf7181

Please sign in to comment.