test: move platform-server integration test (#22810)
Now it lives in our standard location for tests against npm packages PR Close #22810
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
built/
|
||||
*/src/*.d.ts
|
||||
*/src/*.js
|
||||
**/*.ngfactory.ts
|
||||
**/*.ngsummary.json
|
||||
npm-debug.log
|
@ -1,7 +0,0 @@
|
||||
To add a new server side rendering E2E test
|
||||
|
||||
- Add a new server side rendered application to src/
|
||||
- Edit webpack.client.config.js to add new entry point for the new client bundle
|
||||
- The index.html can access the client bundle from /built/<bundle-name>.js
|
||||
- Edit src/server.ts to add the server side application to a new URL
|
||||
- Add a protractor test in e2e/ to test with the new URL
|
@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
rm -rf built
|
||||
|
||||
ngc
|
||||
|
||||
# This is to mainlt copy the index.html to be packaged into the server.
|
||||
cp -r src/* built/src
|
||||
|
||||
# Bundle the server which hosts all the server side apps.
|
||||
webpack --config webpack.server.config.js
|
||||
|
||||
# Bundle the clients into individual bundles.
|
||||
webpack --config webpack.client.config.js
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {browser, by, element} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from './util';
|
||||
|
||||
describe('Hello world E2E Tests', function() {
|
||||
it('should display: Hello world!', function() {
|
||||
// Load the page without waiting for Angular since it is not bootstrapped automatically.
|
||||
browser.driver.get(browser.baseUrl + 'helloworld');
|
||||
|
||||
const style = browser.driver.findElement(by.css('style[ng-transition="hlw"]'));
|
||||
expect(style.getText()).not.toBeNull();
|
||||
|
||||
// Test the contents from the server.
|
||||
const serverDiv = browser.driver.findElement(by.css('div'));
|
||||
expect(serverDiv.getText()).toEqual('Hello world!');
|
||||
|
||||
// Bootstrap the client side app.
|
||||
browser.executeScript('doBootstrap()');
|
||||
|
||||
// Retest the contents after the client bootstraps.
|
||||
expect(element(by.css('div')).getText()).toEqual('Hello world!');
|
||||
|
||||
// Make sure the server styles got replaced by client side ones.
|
||||
expect(element(by.css('style[ng-transition="hlw"]')).isPresent()).toBe(false);
|
||||
expect(element(by.css('style')).getText()).toBe('');
|
||||
|
||||
// Make sure there were no client side errors.
|
||||
verifyNoBrowserErrors();
|
||||
});
|
||||
});
|
@ -1,22 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
exports.config = {
|
||||
specs: ['../built/e2e/*-spec.js'],
|
||||
capabilities: {
|
||||
browserName: 'chrome',
|
||||
chromeOptions: {
|
||||
args: ['--no-sandbox'],
|
||||
binary: process.env.CHROME_BIN,
|
||||
}
|
||||
},
|
||||
directConnect: true,
|
||||
baseUrl: 'http://localhost:9876/',
|
||||
framework: 'jasmine',
|
||||
useAllAngular2AppRoots: true
|
||||
};
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {browser, by, element} from 'protractor';
|
||||
|
||||
import {verifyNoBrowserErrors} from './util';
|
||||
|
||||
describe('TransferState', function() {
|
||||
it('should transfer component state', function() {
|
||||
// Load the page without waiting for Angular since it is not bootstrapped automatically.
|
||||
browser.driver.get(browser.baseUrl + 'transferstate');
|
||||
|
||||
// Test the contents from the server.
|
||||
const serverDiv = browser.driver.findElement(by.css('div'));
|
||||
expect(serverDiv.getText()).toEqual('5');
|
||||
|
||||
// Bootstrap the client side app and retest the contents
|
||||
browser.executeScript('doBootstrap()');
|
||||
expect(element(by.css('div')).getText()).toEqual('50');
|
||||
|
||||
// Make sure there were no client side errors.
|
||||
verifyNoBrowserErrors();
|
||||
});
|
||||
});
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "../built/e2e",
|
||||
"types": ["jasmine"],
|
||||
// TODO(alexeagle): was required for Protractor 4.0.11
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
/* tslint:disable:no-console */
|
||||
import * as webdriver from 'selenium-webdriver';
|
||||
declare var browser: any;
|
||||
declare var expect: any;
|
||||
|
||||
export function verifyNoBrowserErrors() {
|
||||
browser.manage().logs().get('browser').then(function(browserLog: any[]) {
|
||||
const errors: any[] = [];
|
||||
browserLog.filter(logEntry => {
|
||||
const msg = logEntry.message;
|
||||
console.log('>> ' + msg);
|
||||
if (logEntry.level.value >= webdriver.logging.Level.INFO.value) {
|
||||
errors.push(msg);
|
||||
}
|
||||
});
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
{
|
||||
"name": "platform-server-integration",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"description": "Integration tests for @angular/platform-server",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/angular/angular.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/animations": "file:../../../dist/packages-dist/animations",
|
||||
"@angular/common": "file:../../../dist/packages-dist/common",
|
||||
"@angular/compiler": "file:../../../dist/packages-dist/compiler",
|
||||
"@angular/compiler-cli": "file:../../../dist/packages-dist/compiler-cli",
|
||||
"@angular/core": "file:../../../dist/packages-dist/core",
|
||||
"@angular/http": "file:../../../dist/packages-dist/http",
|
||||
"@angular/platform-browser": "file:../../../dist/packages-dist/platform-browser",
|
||||
"@angular/platform-browser-dynamic": "file:../../../dist/packages-dist/platform-browser-dynamic",
|
||||
"@angular/platform-server": "file:../../../dist/packages-dist/platform-server",
|
||||
"express": "^4.14.1",
|
||||
"rxjs": "file:../../../node_modules/rxjs",
|
||||
"typescript": "file:../../../node_modules/typescript",
|
||||
"zone.js": "file:../../../node_modules/zone.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jasmine": "2.5.41",
|
||||
"babel-core": "^6.23.1",
|
||||
"babel-loader": "^6.4.0",
|
||||
"babel-preset-es2015": "^6.22.0",
|
||||
"concurrently": "3.1.0",
|
||||
"protractor": "file:../../../node_modules/protractor",
|
||||
"raw-loader": "^0.5.1",
|
||||
"webpack": "^2.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG",
|
||||
"build": "./build.sh",
|
||||
"test": "npm run build && concurrently \"npm run serve\" \"npm run protractor\" --kill-others --success first",
|
||||
"serve": "node built/server-bundle.js",
|
||||
"preprotractor": "tsc -p e2e",
|
||||
"protractor": "protractor e2e/protractor.config.js"
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu -o pipefail
|
||||
|
||||
cd `dirname $0`
|
||||
|
||||
echo "#################################"
|
||||
echo "Running platform-server end to end tests"
|
||||
echo "#################################"
|
||||
|
||||
yarn install
|
||||
|
||||
npm run test
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {ServerModule} from '@angular/platform-server';
|
||||
|
||||
import {HelloWorldModule} from './app';
|
||||
import {HelloWorldComponent} from './hello-world.component';
|
||||
|
||||
@NgModule({
|
||||
bootstrap: [HelloWorldComponent],
|
||||
imports: [HelloWorldModule, ServerModule],
|
||||
})
|
||||
export class HelloWorldServerModule {
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
import {HelloWorldComponent} from './hello-world.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [HelloWorldComponent],
|
||||
bootstrap: [HelloWorldComponent],
|
||||
imports: [BrowserModule.withServerTransition({appId: 'hlw'})],
|
||||
})
|
||||
export class HelloWorldModule {
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import 'zone.js/dist/zone.js';
|
||||
|
||||
import {enableProdMode} from '@angular/core';
|
||||
import {platformBrowser} from '@angular/platform-browser';
|
||||
import {HelloWorldModuleNgFactory} from './app.ngfactory';
|
||||
|
||||
window['doBootstrap'] = function() {
|
||||
platformBrowser().bootstrapModuleFactory(HelloWorldModuleNgFactory);
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'hello-world-app',
|
||||
template: `
|
||||
<div>Hello {{ name }}!</div>
|
||||
`,
|
||||
styles: [`
|
||||
div {
|
||||
font-weight: bold;
|
||||
}
|
||||
`]
|
||||
})
|
||||
export class HelloWorldComponent {
|
||||
name: string = 'world';
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello World</title>
|
||||
<script src="built/helloworld-bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<hello-world-app></hello-world-app>
|
||||
</body>
|
||||
</html>
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
/* tslint:disable:no-console */
|
||||
require('zone.js/dist/zone-node.js');
|
||||
|
||||
import {enableProdMode, NgModuleFactory} from '@angular/core';
|
||||
import {renderModuleFactory} from '@angular/platform-server';
|
||||
import * as express from 'express';
|
||||
|
||||
import {HelloWorldServerModuleNgFactory} from './helloworld/app.server.ngfactory';
|
||||
const helloworld = require('raw-loader!./helloworld/index.html');
|
||||
|
||||
import {TransferStateServerModuleNgFactory} from './transferstate/app.server.ngfactory';
|
||||
const transferstate = require('raw-loader!./transferstate/index.html');
|
||||
|
||||
const app = express();
|
||||
|
||||
function render<T>(moduleFactory: NgModuleFactory<T>, html: string) {
|
||||
return (req, res) => {
|
||||
renderModuleFactory(moduleFactory, {
|
||||
document: html,
|
||||
url: req.url,
|
||||
}).then((response) => { res.send(response); });
|
||||
};
|
||||
}
|
||||
|
||||
enableProdMode();
|
||||
|
||||
// Client bundles will be statically served from the built/ directory.
|
||||
app.use('/built', express.static('built'));
|
||||
|
||||
// Keep the browser logs free of errors.
|
||||
app.get('/favicon.ico', (req, res) => { res.send(''); });
|
||||
|
||||
//-----------ADD YOUR SERVER SIDE RENDERED APP HERE ----------------------
|
||||
app.get('/helloworld', render(HelloWorldServerModuleNgFactory, helloworld));
|
||||
app.get('/transferstate', render(TransferStateServerModuleNgFactory, transferstate));
|
||||
|
||||
app.listen(9876, function() { console.log('Server listening on port 9876!'); });
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {ServerModule, ServerTransferStateModule} from '@angular/platform-server';
|
||||
|
||||
import {TransferStateModule} from './app';
|
||||
import {TransferStateComponent} from './transfer-state.component';
|
||||
|
||||
@NgModule({
|
||||
bootstrap: [TransferStateComponent],
|
||||
imports: [TransferStateModule, ServerModule, ServerTransferStateModule],
|
||||
})
|
||||
export class TransferStateServerModule {
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BrowserModule, BrowserTransferStateModule} from '@angular/platform-browser';
|
||||
|
||||
import {TransferStateComponent} from './transfer-state.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [TransferStateComponent],
|
||||
bootstrap: [TransferStateComponent],
|
||||
imports: [
|
||||
BrowserModule.withServerTransition({appId: 'ts'}),
|
||||
BrowserTransferStateModule,
|
||||
],
|
||||
})
|
||||
export class TransferStateModule {
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import 'zone.js/dist/zone.js';
|
||||
|
||||
import {enableProdMode} from '@angular/core';
|
||||
import {platformBrowser} from '@angular/platform-browser';
|
||||
import {TransferStateModuleNgFactory} from './app.ngfactory';
|
||||
|
||||
window['doBootstrap'] = function() {
|
||||
platformBrowser().bootstrapModuleFactory(TransferStateModuleNgFactory);
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello World</title>
|
||||
<script src="built/transferstate-bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<transfer-state-app></transfer-state-app>
|
||||
</body>
|
||||
</html>
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {isPlatformServer} from '@angular/common';
|
||||
import {Component, Inject, PLATFORM_ID} from '@angular/core';
|
||||
import {StateKey, TransferState, makeStateKey} from '@angular/platform-browser';
|
||||
|
||||
const COUNTER_KEY = makeStateKey<number>('counter');
|
||||
|
||||
@Component({
|
||||
selector: 'transfer-state-app',
|
||||
template: `
|
||||
<div>{{counter}}</div>
|
||||
`,
|
||||
})
|
||||
export class TransferStateComponent {
|
||||
counter = 0;
|
||||
|
||||
constructor(@Inject(PLATFORM_ID) private platformId: {}, private transferState: TransferState) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (isPlatformServer(this.platformId)) {
|
||||
// Set it to 5 in the server.
|
||||
this.counter = 5;
|
||||
this.transferState.set(COUNTER_KEY, 50);
|
||||
} else {
|
||||
// Get the transferred counter state in the client(should be 50 and not 0).
|
||||
this.counter = this.transferState.get(COUNTER_KEY, 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
{
|
||||
"angularCompilerOptions": {
|
||||
"annotationsAs": "static fields",
|
||||
"annotateForClosureCompiler": true
|
||||
},
|
||||
|
||||
"compilerOptions": {
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
// TODO(i): strictNullChecks should turned on but are temporarily disabled due to #15432
|
||||
"strictNullChecks": false,
|
||||
"target": "es6",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"experimentalDecorators": true,
|
||||
"outDir": "built",
|
||||
"rootDir": ".",
|
||||
"declaration": true,
|
||||
"typeRoots": ["node_modules/@types"]
|
||||
},
|
||||
|
||||
"exclude": [
|
||||
"vendor",
|
||||
"node_modules",
|
||||
"built",
|
||||
"dist",
|
||||
"e2e"
|
||||
]
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
helloworld: './built/src/helloworld/client.js',
|
||||
transferstate: './built/src/transferstate/client.js',
|
||||
},
|
||||
output: {path: path.join(__dirname, 'built'), filename: '[name]-bundle.js'},
|
||||
module: {loaders: [{test: /\.js$/, loader: 'babel-loader?presets[]=es2015'}]},
|
||||
resolve: {extensions: ['.js']}
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
target: 'node',
|
||||
entry: './built/src/server.js',
|
||||
output: {filename: './built/server-bundle.js'},
|
||||
resolve: {extensions: ['.js']},
|
||||
};
|
Reference in New Issue
Block a user