Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit e188e47

Browse files
committed
docs(e2e-tests): improve gulp e2e tasks and fix samples that were failing
1 parent f9fea00 commit e188e47

File tree

11 files changed

+112
-70
lines changed

11 files changed

+112
-70
lines changed

gulpfile.js

+73-36
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,46 @@ var _exampleBoilerplateFiles = [
8686

8787
var _exampleDartWebBoilerPlateFiles = ['styles.css'];
8888

89-
// --filter may be passed in to filter/select _example app subdir names
90-
// i.e. gulp run-e2e-tests --filter=foo ; would select all example apps with
91-
// 'foo' in their folder names.
89+
/**
90+
* Run Protractor End-to-End Tests for Doc Samples
91+
*
92+
* Flags
93+
* --filter to filter/select _example app subdir names
94+
* e.g. gulp run-e2e-tests --filter=foo // all example apps with 'foo' in their folder names.
95+
*
96+
* --fast by-passes the npm install and webdriver update
97+
* Use it for repeated test runs (but not the FIRST run)
98+
* e.g. gulp run-e2e-tests --fast
99+
*
100+
* --lang to filter by code language
101+
* e.g. gulp run-e2e-tests --lang=ts // only TypeScript apps
102+
* default is (ts|js)
103+
* all means (ts|js|dart)
104+
*/
92105
gulp.task('run-e2e-tests', function() {
93-
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
94-
return spawnInfo.promise.then(function() {
95-
copyExampleBoilerplate();
96-
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
97-
spawnInfo = spawnExt('webdriver-manager', ['update'], {cwd: exePath});
98-
return spawnInfo.promise;
99-
}).then(function() {
106+
107+
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
108+
109+
var promise;
110+
if (argv.fast) {
111+
// fast; skip all setup
112+
promise = Promise.resolve(true);
113+
} else {
114+
// Not 'fast'; do full setup
115+
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
116+
promise = spawnInfo.promise.then(function() {
117+
copyExampleBoilerplate();
118+
spawnInfo = spawnExt('webdriver-manager', ['update'], {cwd: exePath});
119+
return spawnInfo.promise;
120+
});
121+
}
122+
123+
promise.then(function() {
100124
return findAndRunE2eTests(argv.filter);
101125
}).then(function(status) {
102126
reportStatus(status);
103-
}).fail(function(e) {
127+
}).catch(function(e) {
128+
gutil.log(e);
104129
return e;
105130
});
106131
});
@@ -114,10 +139,13 @@ function findAndRunE2eTests(filter) {
114139
var startTime = new Date().getTime();
115140
// create an output file with header.
116141
var outputFile = path.join(process.cwd(), 'protractor-results.txt');
117-
var header = "Protractor example results for " + lang + " on " + (new Date()).toLocaleString() + "\n\n";
118-
if (filter) {
119-
header += ' Filter: ' + filter.toString() + '\n\n';
120-
}
142+
143+
var header = `Doc Sample Protractor Results for ${lang} on ${new Date().toLocaleString()}\n`;
144+
header += argv.fast ?
145+
' Fast Mode (--fast): no npm install, webdriver update, or boilerplate copy\n' :
146+
' Slow Mode: npm install, webdriver update, and boilerplate copy\n';
147+
header += ` Filter: ${filter ? filter : 'All tests'}\n\n`;
148+
121149
fs.writeFileSync(outputFile, header);
122150

123151
// create an array of combos where each
@@ -175,25 +203,32 @@ function runE2eTsTests(appDir, protractorConfigFilename, outputFile) {
175203
}
176204

177205
function runProtractor(prepPromise, appDir, appRunSpawnInfo, protractorConfigFilename, outputFile) {
178-
return prepPromise.then(function (data) {
179-
// start protractor
180-
var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir
181-
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
182-
var spawnInfo = spawnExt('protractor',
183-
[ pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath });
184-
return spawnInfo.promise;
185-
}).then(function(data) {
186-
// kill the app now that protractor has completed.
187-
// Ugh... proc.kill does not work properly on windows with child processes.
188-
// appRun.proc.kill();
189-
treeKill(appRunSpawnInfo.proc.pid);
190-
return !data;
191-
}).fail(function(err) {
192-
// Ugh... proc.kill does not work properly on windows with child processes.
193-
// appRun.proc.kill();
194-
treeKill(appRunSpawnInfo.proc.pid);
195-
return false;
196-
});
206+
return prepPromise
207+
.catch(function(){
208+
var emsg = `AppDir failed during compile: ${appDir}\n\n`;
209+
gutil.log(emsg);
210+
fs.appendFileSync(outputFile, emsg);
211+
return Promise.reject(emsg);
212+
})
213+
.then(function (data) {
214+
// start protractor
215+
var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir
216+
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
217+
var spawnInfo = spawnExt('protractor',
218+
[ pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath });
219+
return spawnInfo.promise
220+
})
221+
.then(
222+
function() { return finish(true);},
223+
function() { return finish(false);}
224+
)
225+
226+
function finish(ok){
227+
// Ugh... proc.kill does not work properly on windows with child processes.
228+
// appRun.proc.kill();
229+
treeKill(appRunSpawnInfo.proc.pid);
230+
return ok;
231+
}
197232
}
198233

199234
// start the server in appDir/build/web; then run protractor with the specified
@@ -252,9 +287,11 @@ function spawnExt(command, args, options) {
252287
proc.stderr.on('data', function (data) {
253288
gutil.log(data.toString());
254289
});
255-
proc.on('close', function (data) {
290+
proc.on('close', function (returnCode) {
256291
gutil.log('completed: ' + descr);
257-
deferred.resolve(data);
292+
// Many tasks (e.g., tsc) complete but are actually errors;
293+
// Confirm return code is zero.
294+
returnCode === 0 ? deferred.resolve(0) : deferred.reject(returnCode);
258295
});
259296
proc.on('error', function (data) {
260297
gutil.log('completed with error:' + descr);

public/docs/_examples/cb-component-communication/ts/app/countdown-timer.component.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Component, OnDestroy, OnInit } from '@angular/core';
33

44
@Component({
5-
selector:'countdown-timer',
5+
selector: 'countdown-timer',
66
template: '<p>{{message}}</p>'
77
})
88
export class CountdownTimerComponent implements OnInit, OnDestroy {
@@ -24,12 +24,12 @@ export class CountdownTimerComponent implements OnInit, OnDestroy {
2424

2525
private countDown() {
2626
this.clearTimer();
27-
this.intervalId = setInterval(()=>{
27+
this.intervalId = window.setInterval(() => {
2828
this.seconds -= 1;
29-
if (this.seconds == 0) {
30-
this.message = "Blast off!";
29+
if (this.seconds === 0) {
30+
this.message = 'Blast off!';
3131
} else {
32-
if (this.seconds < 0) { this.seconds = 10;} // reset
32+
if (this.seconds < 0) { this.seconds = 10; } // reset
3333
this.message = `T-${this.seconds} seconds and counting`;
3434
}
3535
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
// gulp run-e2e-tests --filter=cb-set-document-title
2-
describe('Set Document Title', function () {
3-
4-
beforeAll(function () {
5-
browser.get('');
6-
});
7-
8-
it('should set the document title', function () {
9-
10-
var titles = [
11-
'Good morning!',
12-
'Good afternoon!',
13-
'Good evening!'
14-
];
15-
16-
element.all( by.css( 'ul li a' ) ).each(
17-
function iterator( element, i ) {
1+
describe('Cookbook: component-relative paths', function () {
2+
3+
function getPageStruct() {
4+
return {
5+
title: element( by.tagName( 'h1' )),
6+
absComp: element( by.css( 'absolute-path div' ) ),
7+
relComp: element( by.css( 'relative-path div' ) )
8+
}
9+
}
10+
11+
var page;
12+
beforeAll(function () {
13+
browser.get('');
14+
page = getPageStruct();
15+
});
1816

19-
element.click();
20-
expect( browser.getTitle() ).toEqual( titles[ i ] );
17+
it('should display title of the sample', function () {
18+
expect(element(by.tagName('h1')).getText()).toContain('Paths');
19+
});
2120

22-
}
23-
);
21+
it('should have absolute-path element', function () {
22+
expect(page.absComp.isPresent()).toBe(true, 'no <absolute-path> element');
23+
});
2424

25+
it('should display the absolute path text', function () {
26+
expect(page.absComp.getText()).toContain('Absolute');
2527
});
2628

29+
it('should display the component-relative path text', function () {
30+
expect(page.relComp.getText()).toContain('Component-relative');
31+
});
2732
});

public/docs/_examples/cb-dependency-injection/ts/app/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LocationStrategy,
88

99
import { HeroData } from './hero-data';
1010
import { InMemoryBackendService,
11-
SEED_DATA } from 'angular2-in-memory-web-api/core';
11+
SEED_DATA } from 'angular2-in-memory-web-api';
1212

1313
import { AppComponent } from './app.component';
1414

public/docs/_examples/karma-test-shim.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var map = {
3838
var packages = {
3939
'app': { main: 'main.js', defaultExtension: 'js' },
4040
'rxjs': { defaultExtension: 'js' },
41-
'angular2-in-memory-web-api': { defaultExtension: 'js' },
41+
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
4242
};
4343

4444
var ngPackageNames = [

public/docs/_examples/server-communication/ts/app/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { provide } from '@angular/core';
55
import { XHRBackend } from '@angular/http';
66

77
import { InMemoryBackendService,
8-
SEED_DATA } from 'angular2-in-memory-web-api/core';
8+
SEED_DATA } from 'angular2-in-memory-web-api';
99
import { HeroData } from './hero-data';
1010

1111
// The usual bootstrapping imports

public/docs/_examples/systemjs.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
var packages = {
1818
'app': { main: 'main.js', defaultExtension: 'js' },
1919
'rxjs': { defaultExtension: 'js' },
20-
'angular2-in-memory-web-api': { defaultExtension: 'js' },
20+
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
2121
};
2222

2323
var ngPackageNames = [

public/docs/_examples/systemjs.config.plunker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var packages = {
2323
'app': { main: 'main.ts', defaultExtension: 'ts' },
2424
'rxjs': { defaultExtension: 'js' },
25-
'angular2-in-memory-web-api': { defaultExtension: 'js' },
25+
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
2626
};
2727

2828
var ngPackageNames = [

public/docs/_examples/toh-6/ts/app/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { provide } from '@angular/core';
55
import { XHRBackend } from '@angular/http';
66

7-
import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api/core';
7+
import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
88
import { InMemoryDataService } from './in-memory-data.service';
99

1010
// The usual bootstrapping imports

public/docs/_examples/wallaby.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = function () {
8484
var packages = {
8585
'app': { main: 'main.js', defaultExtension: 'js' },
8686
'rxjs': { defaultExtension: 'js' },
87-
'angular2-in-memory-web-api': { defaultExtension: 'js' },
87+
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
8888
};
8989

9090
var ngPackageNames = [

public/docs/ts/latest/cookbook/component-relative-paths.jade

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ include ../_util-fns
8484
cb-component-relative-paths/ts/app/some.component.css,
8585
cb-component-relative-paths/ts/app/app.component.ts`,
8686
null,
87-
`app/some.component.ts, app/some.html, app/some.component.css, app/app.component.ts`)
87+
`app/some.component.ts, app/some.component.html, app/some.component.css, app/app.component.ts`)
8888

8989
a#why-default
9090
.l-main-section

0 commit comments

Comments
 (0)