@@ -38,6 +38,7 @@ var TEMP_PATH = './_temp';
38
38
var DOCS_PATH = path . join ( PUBLIC_PATH , 'docs' ) ;
39
39
40
40
var EXAMPLES_PATH = path . join ( DOCS_PATH , '_examples' ) ;
41
+ var EXAMPLES_PROTRACTOR_PATH = path . join ( EXAMPLES_PATH , '_protractor' ) ;
41
42
var NOT_API_DOCS_GLOB = path . join ( PUBLIC_PATH , './{docs/*/latest/!(api),!(docs)}/**/*' ) ;
42
43
var RESOURCES_PATH = path . join ( PUBLIC_PATH , 'resources' ) ;
43
44
var LIVE_EXAMPLES_PATH = path . join ( RESOURCES_PATH , 'live-examples' ) ;
@@ -86,123 +87,150 @@ var _exampleBoilerplateFiles = [
86
87
87
88
var _exampleDartWebBoilerPlateFiles = [ 'styles.css' ] ;
88
89
90
+ var _exampleProtractorBoilerplateFiles = [
91
+ 'tsconfig.json'
92
+ ] ;
93
+
94
+ /**
95
+ * Run Protractor End-to-End Specs for Doc Samples
96
+ * Alias for 'run-e2e-tests'
97
+ */
98
+ gulp . task ( 'e2e' , runE2e ) ;
99
+
100
+ gulp . task ( 'run-e2e-tests' , runE2e ) ;
101
+
89
102
/**
90
103
* Run Protractor End-to-End Tests for Doc Samples
91
104
*
92
105
* Flags
93
106
* --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.
107
+ * e.g. gulp e2e --filter=foo // all example apps with 'foo' in their folder names.
95
108
*
96
109
* --fast by-passes the npm install and webdriver update
97
110
* Use it for repeated test runs (but not the FIRST run)
98
- * e.g. gulp run- e2e-tests --fast
111
+ * e.g. gulp e2e --fast
99
112
*
100
113
* --lang to filter by code language
101
- * e.g. gulp run- e2e-tests --lang=ts // only TypeScript apps
114
+ * e.g. gulp e2e --lang=ts // only TypeScript apps
102
115
* default is (ts|js)
103
116
* all means (ts|js|dart)
104
117
*/
105
- gulp . task ( 'run-e2e-tests' , function ( ) {
118
+ function runE2e ( ) {
106
119
var promise ;
107
120
if ( argv . fast ) {
108
121
// fast; skip all setup
109
122
promise = Promise . resolve ( true ) ;
110
123
} else {
111
- // Not 'fast'; do full setup
124
+ /*
125
+ // Not 'fast'; do full setup
112
126
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
113
127
promise = spawnInfo.promise.then(function() {
114
128
copyExampleBoilerplate();
115
129
spawnInfo = spawnExt('npm', ['run', 'webdriver:update'], {cwd: EXAMPLES_PATH});
116
130
return spawnInfo.promise;
117
131
});
118
- }
132
+ */
133
+ // Not 'fast'; do full setup
134
+ gutil . log ( 'runE2e: install _protractor stuff' ) ;
135
+ var spawnInfo = spawnExt ( 'npm' , [ 'install' ] , { cwd : EXAMPLES_PROTRACTOR_PATH } ) ;
136
+ promise = spawnInfo . promise
137
+ . then ( function ( ) {
138
+ gutil . log ( 'runE2e: install _examples stuff' ) ;
139
+ spawnInfo = spawnExt ( 'npm' , [ 'install' ] , { cwd : EXAMPLES_PATH } )
140
+ return spawnInfo . promise ;
141
+ } )
142
+ . then ( function ( ) {
143
+ copyExampleBoilerplate ( ) ;
144
+ gutil . log ( 'runE2e: update webdriver' ) ;
145
+ spawnInfo = spawnExt ( 'npm' , [ 'run' , 'webdriver:update' ] , { cwd : EXAMPLES_PROTRACTOR_PATH } ) ;
146
+ return spawnInfo . promise ;
147
+ } ) ;
148
+ } ;
149
+
150
+ var outputFile = path . join ( process . cwd ( ) , 'protractor-results.txt' ) ;
119
151
120
152
promise . then ( function ( ) {
121
- return findAndRunE2eTests ( argv . filter ) ;
153
+ return findAndRunE2eTests ( argv . filter , outputFile ) ;
122
154
} ) . then ( function ( status ) {
123
- reportStatus ( status ) ;
155
+ reportStatus ( status , outputFile ) ;
124
156
if ( status . failed . length > 0 ) {
125
157
return Promise . reject ( 'Some test suites failed' ) ;
126
158
}
127
159
} ) . catch ( function ( e ) {
128
160
gutil . log ( e ) ;
129
- process . exit ( 1 ) ;
161
+ process . exitCode = 1 ;
130
162
} ) ;
131
- } ) ;
163
+ return promise ;
164
+ }
132
165
133
166
// finds all of the *e2e-spec.tests under the _examples folder along
134
167
// with the corresponding apps that they should run under. Then run
135
168
// each app/spec collection sequentially.
136
- function findAndRunE2eTests ( filter ) {
169
+ function findAndRunE2eTests ( filter , outputFile ) {
170
+
171
+ // create an output file with header.
137
172
var lang = ( argv . lang || '(ts|js)' ) . toLowerCase ( ) ;
138
173
if ( lang === 'all' ) { lang = '(ts|js|dart)' ; }
139
174
var startTime = new Date ( ) . getTime ( ) ;
140
- // create an output file with header.
141
- var outputFile = path . join ( process . cwd ( ) , 'protractor-results.txt' ) ;
142
-
143
175
var header = `Doc Sample Protractor Results for ${ lang } on ${ new Date ( ) . toLocaleString ( ) } \n` ;
144
176
header += argv . fast ?
145
177
' Fast Mode (--fast): no npm install, webdriver update, or boilerplate copy\n' :
146
178
' Slow Mode: npm install, webdriver update, and boilerplate copy\n' ;
147
179
header += ` Filter: ${ filter ? filter : 'All tests' } \n\n` ;
148
-
149
180
fs . writeFileSync ( outputFile , header ) ;
150
181
151
182
// create an array of combos where each
152
183
// combo consists of { examplePath: ... , protractorConfigFilename: ... }
153
- var exeConfigs = [ ] ;
184
+ var examplePaths = [ ] ;
154
185
var e2eSpecPaths = getE2eSpecPaths ( EXAMPLES_PATH ) ;
155
- var srcConfig = path . join ( EXAMPLES_PATH , 'protractor.config.js' ) ;
156
- e2eSpecPaths . forEach ( function ( specPath ) {
186
+ e2eSpecPaths . forEach ( function ( specPath ) {
157
187
var destConfig = path . join ( specPath , 'protractor.config.js' ) ;
158
- fsExtra . copySync ( srcConfig , destConfig ) ;
159
188
// get all of the examples under each dir where a pcFilename is found
160
- examplePaths = getExamplePaths ( specPath , true ) ;
189
+ localExamplePaths = getExamplePaths ( specPath , true ) ;
161
190
// Filter by language
162
- examplePaths = examplePaths . filter ( function ( fn ) {
191
+ localExamplePaths = localExamplePaths . filter ( function ( fn ) {
163
192
return fn . match ( '/' + lang + '$' ) != null ;
164
193
} ) ;
165
194
if ( filter ) {
166
- examplePaths = examplePaths . filter ( function ( fn ) {
195
+ localExamplePaths = localExamplePaths . filter ( function ( fn ) {
167
196
return fn . match ( filter ) != null ;
168
197
} )
169
198
}
170
- examplePaths . forEach ( function ( exPath ) {
171
- exeConfigs . push ( { examplePath : exPath , protractorConfigFilename : destConfig } ) ;
199
+ localExamplePaths . forEach ( function ( examplePath ) {
200
+ examplePaths . push ( examplePath ) ;
172
201
} )
173
202
} ) ;
174
203
175
204
// run the tests sequentially
176
205
var status = { passed : [ ] , failed : [ ] } ;
177
- return exeConfigs . reduce ( function ( promise , combo ) {
206
+ return examplePaths . reduce ( function ( promise , examplePath ) {
178
207
return promise . then ( function ( ) {
179
- var isDart = combo . examplePath . indexOf ( '/dart' ) > - 1 ;
208
+ var isDart = examplePath . indexOf ( '/dart' ) > - 1 ;
180
209
var runTests = isDart ? runE2eDartTests : runE2eTsTests ;
181
- return runTests ( combo . examplePath , combo . protractorConfigFilename , outputFile ) . then ( function ( ok ) {
210
+ return runTests ( examplePath , outputFile ) . then ( function ( ok ) {
182
211
var arr = ok ? status . passed : status . failed ;
183
- arr . push ( combo . examplePath ) ;
212
+ arr . push ( examplePath ) ;
184
213
} )
185
214
} ) ;
186
215
} , Q . resolve ( ) ) . then ( function ( ) {
187
216
var stopTime = new Date ( ) . getTime ( ) ;
188
217
status . elapsedTime = ( stopTime - startTime ) / 1000 ;
189
- fs . appendFileSync ( outputFile , '\nElaped Time: ' + status . elapsedTime + ' seconds' ) ;
190
218
return status ;
191
219
} ) ;
192
220
}
193
221
194
222
// start the example in appDir; then run protractor with the specified
195
223
// fileName; then shut down the example. All protractor output is appended
196
224
// to the outputFile.
197
- function runE2eTsTests ( appDir , protractorConfigFilename , outputFile ) {
225
+ function runE2eTsTests ( appDir , outputFile ) {
198
226
// start the app
199
227
var appRunSpawnInfo = spawnExt ( 'npm' , [ 'run' , 'http-server:e2e' , '--' , '-s' ] , { cwd : appDir } ) ;
200
228
var tscRunSpawnInfo = spawnExt ( 'npm' , [ 'run' , 'tsc' ] , { cwd : appDir } ) ;
201
229
202
- return runProtractor ( tscRunSpawnInfo . promise , appDir , appRunSpawnInfo , protractorConfigFilename , outputFile ) ;
230
+ return runProtractor ( tscRunSpawnInfo . promise , appDir , appRunSpawnInfo , outputFile ) ;
203
231
}
204
232
205
- function runProtractor ( prepPromise , appDir , appRunSpawnInfo , protractorConfigFilename , outputFile ) {
233
+ function runProtractor ( prepPromise , appDir , appRunSpawnInfo , outputFile ) {
206
234
return prepPromise
207
235
. catch ( function ( ) {
208
236
var emsg = `AppDir failed during compile: ${ appDir } \n\n` ;
@@ -212,10 +240,10 @@ function runProtractor(prepPromise, appDir, appRunSpawnInfo, protractorConfigFil
212
240
} )
213
241
. then ( function ( data ) {
214
242
// start protractor
215
- var pcFilename = path . resolve ( protractorConfigFilename ) ; // need to resolve because we are going to be running from a different dir
216
- var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'protractor' , '--' , pcFilename ,
217
- '--params.appDir=' + appDir , '--params.outputFile=' + outputFile ] , { cwd : EXAMPLES_PATH } ) ;
218
- return spawnInfo . promise
243
+ var specFilename = path . resolve ( ` ${ appDir } /../e2e-spec.ts` ) ;
244
+ var spawnInfo = spawnExt ( 'npm' , [ 'run' , 'protractor' , '--' , 'protractor.config.js' ,
245
+ `--specs= ${ specFilename } ` , '--params.appDir=' + appDir , '--params.outputFile=' + outputFile ] , { cwd : EXAMPLES_PROTRACTOR_PATH } ) ;
246
+ return spawnInfo . promise ;
219
247
} )
220
248
. then (
221
249
function ( ) { return finish ( true ) ; } ,
@@ -233,7 +261,7 @@ function runProtractor(prepPromise, appDir, appRunSpawnInfo, protractorConfigFil
233
261
// start the server in appDir/build/web; then run protractor with the specified
234
262
// fileName; then shut down the example. All protractor output is appended
235
263
// to the outputFile.
236
- function runE2eDartTests ( appDir , protractorConfigFilename , outputFile ) {
264
+ function runE2eDartTests ( appDir , outputFile ) {
237
265
var deployDir = path . resolve ( path . join ( appDir , 'build/web' ) ) ;
238
266
gutil . log ( 'AppDir for Dart e2e: ' + appDir ) ;
239
267
gutil . log ( 'Deploying from: ' + deployDir ) ;
@@ -247,24 +275,28 @@ function runE2eDartTests(appDir, protractorConfigFilename, outputFile) {
247
275
var prepPromise = pubUpgradeSpawnInfo . promise . then ( function ( data ) {
248
276
return spawnExt ( 'pub' , [ 'build' ] , { cwd : appDir } ) . promise ;
249
277
} ) ;
250
- return runProtractor ( prepPromise , appDir , appRunSpawnInfo , protractorConfigFilename , outputFile ) ;
278
+ return runProtractor ( prepPromise , appDir , appRunSpawnInfo , outputFile ) ;
251
279
}
252
280
253
- function reportStatus ( status ) {
254
- gutil . log ( 'Suites passed:' ) ;
281
+ function reportStatus ( status , outputFile ) {
282
+ var log = [ '' ] ;
283
+ log . push ( 'Suites passed:' ) ;
255
284
status . passed . forEach ( function ( val ) {
256
- gutil . log ( ' ' + val ) ;
285
+ log . push ( ' ' + val ) ;
257
286
} ) ;
258
287
259
288
if ( status . failed . length == 0 ) {
260
- gutil . log ( 'All tests passed' ) ;
289
+ log . push ( 'All tests passed' ) ;
261
290
} else {
262
- gutil . log ( 'Suites failed:' ) ;
291
+ log . push ( 'Suites failed:' ) ;
263
292
status . failed . forEach ( function ( val ) {
264
- gutil . log ( ' ' + val ) ;
293
+ log . push ( ' ' + val ) ;
265
294
} ) ;
266
295
}
267
- gutil . log ( 'Elapsed time: ' + status . elapsedTime + ' seconds' ) ;
296
+ log . push ( '\nElapsed time: ' + status . elapsedTime + ' seconds' ) ;
297
+ var log = log . join ( '\n' ) ;
298
+ gutil . log ( log ) ;
299
+ fs . appendFileSync ( outputFile , log ) ;
268
300
}
269
301
270
302
// returns both a promise and the spawned process so that it can be killed if needed.
@@ -312,7 +344,7 @@ gulp.task('help', taskListing.withFilters(function(taskName) {
312
344
return shouldRemove ;
313
345
} ) ) ;
314
346
315
- // requires admin access
347
+ // requires admin access because it adds symlinks
316
348
gulp . task ( 'add-example-boilerplate' , function ( ) {
317
349
var realPath = path . join ( EXAMPLES_PATH , '/node_modules' ) ;
318
350
var nodeModulesPaths = getNodeModulesPaths ( EXAMPLES_PATH ) ;
@@ -332,11 +364,18 @@ gulp.task('add-example-boilerplate', function() {
332
364
return copyExampleBoilerplate ( ) ;
333
365
} ) ;
334
366
367
+
368
+ // copies boilerplate files to locations
369
+ // where an example app is found
370
+ gulp . task ( '_copy-example-boilerplate' , copyExampleBoilerplate ) ;
371
+
372
+
335
373
// copies boilerplate files to locations
336
374
// where an example app is found
337
375
// also copies certain web files (e.g., styles.css) to ~/_examples/**/dart/**/web
338
376
// also copies protractor.config.js file
339
377
function copyExampleBoilerplate ( ) {
378
+ gutil . log ( 'Copying example boilerplate files' ) ;
340
379
var sourceFiles = _exampleBoilerplateFiles . map ( function ( fn ) {
341
380
return path . join ( EXAMPLES_PATH , fn ) ;
342
381
} ) ;
@@ -351,12 +390,14 @@ function copyExampleBoilerplate() {
351
390
. then ( function ( ) {
352
391
return copyFiles ( dartWebSourceFiles , dartExampleWebPaths ) ;
353
392
} )
354
- // copy protractor.config.js from _examples dir to each subdir that
393
+ // copy files from _examples/_protractor dir to each subdir that
355
394
// contains a e2e-spec file.
356
395
. then ( function ( ) {
357
- var sourceFiles = [ path . join ( EXAMPLES_PATH , 'protractor.config.js' ) ] ;
396
+ var protractorSourceFiles =
397
+ _exampleProtractorBoilerplateFiles
398
+ . map ( function ( name ) { return path . join ( EXAMPLES_PROTRACTOR_PATH , name ) ; } ) ; ;
358
399
var e2eSpecPaths = getE2eSpecPaths ( EXAMPLES_PATH ) ;
359
- return copyFiles ( sourceFiles , e2eSpecPaths ) ;
400
+ return copyFiles ( protractorSourceFiles , e2eSpecPaths ) ;
360
401
} ) ;
361
402
}
362
403
@@ -371,6 +412,15 @@ gulp.task('remove-example-boilerplate', function() {
371
412
fsUtils . removeSymlink ( linkPath ) ;
372
413
} ) ;
373
414
415
+ deleteExampleBoilerPlate ( ) ;
416
+ } ) ;
417
+
418
+ // deletes boilerplate files that were added by copyExampleBoilerplate
419
+ // from locations where an example app is found
420
+ gulp . task ( '_delete-example-boilerplate' , deleteExampleBoilerPlate ) ;
421
+
422
+ function deleteExampleBoilerPlate ( ) {
423
+ gutil . log ( 'Deleting example boilerplate files' ) ;
374
424
var examplePaths = getExamplePaths ( EXAMPLES_PATH ) ;
375
425
var dartExampleWebPaths = getDartExampleWebPaths ( EXAMPLES_PATH ) ;
376
426
@@ -379,10 +429,11 @@ gulp.task('remove-example-boilerplate', function() {
379
429
return deleteFiles ( _exampleDartWebBoilerPlateFiles , dartExampleWebPaths ) ;
380
430
} )
381
431
. then ( function ( ) {
432
+ var protractorFiles = _exampleProtractorBoilerplateFiles ;
382
433
var e2eSpecPaths = getE2eSpecPaths ( EXAMPLES_PATH ) ;
383
- return deleteFiles ( [ 'protractor.config.js' ] , e2eSpecPaths ) ;
384
- } )
385
- } ) ;
434
+ return deleteFiles ( protractorFiles , e2eSpecPaths ) ;
435
+ } ) ;
436
+ }
386
437
387
438
gulp . task ( 'serve-and-sync' , [ 'build-docs' ] , function ( cb ) {
388
439
// watchAndSync({devGuide: true, apiDocs: true, apiExamples: true, localFiles: true}, cb);
@@ -744,7 +795,7 @@ function deleteFiles(baseFileNames, destPaths) {
744
795
// TODO: filter out all paths that are subdirs of another
745
796
// path in the result.
746
797
function getE2eSpecPaths ( basePath ) {
747
- var paths = getPaths ( basePath , '*e2e-spec.js ' , true ) ;
798
+ var paths = getPaths ( basePath , '*e2e-spec.+(js|ts) ' , true ) ;
748
799
return _ . uniq ( paths ) ;
749
800
}
750
801
0 commit comments