fix(build): test example directories with unit and e2e tests (#11296)
This commit is contained in:

committed by
Evan Martin

parent
567900e550
commit
ed2ebeb52a
17
modules/@angular/examples/_common/bootstrap.ts
Normal file
17
modules/@angular/examples/_common/bootstrap.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
(function(global: any) {
|
||||
writeScriptTag('/vendor/zone.js');
|
||||
writeScriptTag('/vendor/system.js');
|
||||
writeScriptTag('/vendor/Reflect.js');
|
||||
writeScriptTag('/_common/system-config.js');
|
||||
|
||||
function writeScriptTag(scriptUrl: string, onload: string = '') {
|
||||
document.write('<script src="' + scriptUrl + '" onload="' + onload + '"></script>');
|
||||
}
|
||||
}(window));
|
25
modules/@angular/examples/_common/e2e_util.ts
Normal file
25
modules/@angular/examples/_common/e2e_util.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @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 * as webdriver from 'selenium-webdriver';
|
||||
declare var browser: any;
|
||||
declare var expect: any;
|
||||
|
||||
// TODO (juliemr): remove this method once this becomes a protractor plugin
|
||||
export function verifyNoBrowserErrors() {
|
||||
browser.manage().logs().get('browser').then(function(browserLog) {
|
||||
var errors: any[] = [];
|
||||
browserLog.filter(logEntry => {
|
||||
var msg = logEntry.message;
|
||||
console.log('>> ' + msg);
|
||||
if (logEntry.level.value >= webdriver.logging.Level.INFO.value) {
|
||||
errors.push(msg);
|
||||
}
|
||||
});
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
}
|
16
modules/@angular/examples/_common/index.html
Normal file
16
modules/@angular/examples/_common/index.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript" src="bootstrap.js"></script>
|
||||
<script type="text/javascript">
|
||||
System.import('main-dynamic').catch(console.error.bind(console));
|
||||
</script>
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<example-app>
|
||||
loading...
|
||||
</example-app>
|
||||
</body>
|
||||
</html>
|
11
modules/@angular/examples/_common/main-dynamic.ts
Normal file
11
modules/@angular/examples/_common/main-dynamic.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @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 {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {AppModule} from './module';
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
19
modules/@angular/examples/_common/module.d.ts
vendored
Normal file
19
modules/@angular/examples/_common/module.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
DO NOT DELETE THIS FILE
|
||||
=======================
|
||||
|
||||
The purpose of this file is to allow `main-dynamic.ts` to be tsc-compiled
|
||||
BEFORE it is copied over to each of the associated example directories
|
||||
within `dist/examples`.
|
||||
|
||||
*/
|
||||
export class AppModule {};
|
28
modules/@angular/examples/_common/system-config.ts
Normal file
28
modules/@angular/examples/_common/system-config.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
System.config({
|
||||
defaultJSExtensions: true,
|
||||
map: {
|
||||
'@angular/common': '/vendor/@angular/common/bundles/common.umd.js',
|
||||
'@angular/compiler': '/vendor/@angular/compiler/bundles/compiler.umd.js',
|
||||
'@angular/core': '/vendor/@angular/core/bundles/core.umd.js',
|
||||
'@angular/forms': '/vendor/@angular/forms/bundles/forms.umd.js',
|
||||
'@angular/http': '/vendor/@angular/forms/bundles/http.umd.js',
|
||||
'@angular/platform-browser':
|
||||
'/vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
|
||||
'@angular/platform-browser-dynamic':
|
||||
'/vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
|
||||
'@angular/router': '/vendor/@angular/router/bundles/router.umd.js',
|
||||
'@angular/upgrade': '/vendor/@angular/upgrade/bundles/upgrade.umd.js',
|
||||
'rxjs': '/vendor/rxjs',
|
||||
},
|
||||
packages: {
|
||||
// rxjs: {format: 'cjs', exports: 'Rx' }
|
||||
rxjs: {defaultExtension: 'js'}
|
||||
}
|
||||
});
|
36
modules/@angular/examples/build.sh
Executable file
36
modules/@angular/examples/build.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# This script is used to compile and copy the contents for each of
|
||||
# example directories over to the dist/examples directory so that they
|
||||
# can be tested with karma and protractor. The `gulp serve-examples` command
|
||||
# can be used to run each of the examples in isolation via http as well.
|
||||
#
|
||||
|
||||
cd `dirname $0`
|
||||
|
||||
DIST="../../../dist/examples";
|
||||
rm -rf -- $DIST
|
||||
$(npm bin)/tsc -p .
|
||||
|
||||
mkdir $DIST/vendor/
|
||||
|
||||
ln -s ../../../dist/packages-dist/ $DIST/vendor/@angular
|
||||
|
||||
for FILE in \
|
||||
../../../node_modules/zone.js/dist/zone.js \
|
||||
../../../node_modules/systemjs/dist/system.js \
|
||||
../../../node_modules/reflect-metadata/Reflect.js \
|
||||
../../../node_modules/rxjs
|
||||
do
|
||||
ln -s $FILE $DIST/vendor/`basename $FILE`
|
||||
done
|
||||
|
||||
for MODULE in `find . -name module.ts`; do
|
||||
FINAL_DIR_PATH=$DIST/`dirname $MODULE`
|
||||
|
||||
echo "==== $MODULE"
|
||||
cp _common/*.html $FINAL_DIR_PATH
|
||||
cp $DIST/_common/*.js $FINAL_DIR_PATH
|
||||
cp $DIST/_common/*.js.map $FINAL_DIR_PATH
|
||||
done
|
@ -7,10 +7,11 @@
|
||||
*/
|
||||
|
||||
// #docregion Component
|
||||
import {Component, animate, state, style, transition, trigger} from '@angular/core';
|
||||
import {Component, NgModule, animate, state, style, transition, trigger} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'my-expando',
|
||||
selector: 'example-app',
|
||||
styles: [`
|
||||
.toggle-container {
|
||||
background-color:white;
|
||||
@ -46,4 +47,9 @@ export class MyExpandoCmp {
|
||||
expand() { this.stateExpression = 'expanded'; }
|
||||
collapse() { this.stateExpression = 'collapsed'; }
|
||||
}
|
||||
|
||||
@NgModule({imports: [BrowserModule], declarations: [MyExpandoCmp], bootstrap: [MyExpandoCmp]})
|
||||
export class AppModule {
|
||||
}
|
||||
|
||||
// #enddocregion
|
||||
|
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @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 {verifyNoBrowserErrors} from '../../../../../_common/e2e_util';
|
||||
|
||||
function waitForElement(selector: string) {
|
||||
var EC = (<any>protractor).ExpectedConditions;
|
||||
// Waits for the element with id 'abc' to be present on the dom.
|
||||
browser.wait(EC.presenceOf($(selector)), 20000);
|
||||
}
|
||||
|
||||
describe('animation example', () => {
|
||||
afterEach(verifyNoBrowserErrors);
|
||||
|
||||
describe('index view', () => {
|
||||
var URL = '/core/animation/ts/dsl/index.html';
|
||||
|
||||
it('should list out the current collection of items', () => {
|
||||
browser.get(URL);
|
||||
waitForElement('.toggle-container');
|
||||
expect(element.all(by.css('.toggle-container')).get(0).getText()).toEqual('Look at this box');
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
export {AppModule} from './animation_example';
|
8
modules/@angular/examples/test.sh
Executable file
8
modules/@angular/examples/test.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd `dirname $0`
|
||||
./build.sh
|
||||
|
||||
gulp serve-examples &
|
||||
|
||||
(cd ../../../ && NODE_PATH=$NODE_PATH:dist/all $(npm bin)/protractor protractor-examples-e2e.conf.js --bundles=true)
|
29
modules/@angular/examples/tsconfig.json
Normal file
29
modules/@angular/examples/tsconfig.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"stripInternal": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../../dist/examples",
|
||||
"paths": {
|
||||
"@angular/*": ["../../../dist/packages-dist/*"],
|
||||
"rxjs/*": ["../../../node_modules/rxjs/*"]
|
||||
},
|
||||
"rootDir": ".",
|
||||
"sourceMap": true,
|
||||
"inlineSources": true,
|
||||
"target": "es5",
|
||||
"lib": ["es2015", "dom"],
|
||||
"skipLibCheck": true,
|
||||
"types": ["jasmine", "protractor", "node"]
|
||||
},
|
||||
"include": [
|
||||
"./_common/*.ts",
|
||||
"./**/module.ts",
|
||||
"./**/test/*.ts",
|
||||
"./**/e2e_test/*.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts",
|
||||
"../../system.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user