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

Commit d3e96e3

Browse files
committed
test(e2e/dart): add support for Dart e2e testing
This task runs the *same e2e test suites as for TS*, since the example apps should behave the same in TS and Dart. For now, only - quickstart - toh (toh-5) tests are enabled. ALL tests are passing!
1 parent 8b1683f commit d3e96e3

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

gulpfile.js

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ gulp.task('run-e2e-tests', function() {
109109
// with the corresponding apps that they should run under. Then run
110110
// each app/spec collection sequentially.
111111
function findAndRunE2eTests(filter) {
112+
var lang = argv.lang || 'ts';
112113
var startTime = new Date().getTime();
113114
// create an output file with header.
114115
var outputFile = path.join(process.cwd(), 'protractor-results.txt');
115-
var header = "Protractor example results for: " + (new Date()).toLocaleString() + "\n\n";
116+
var header = "Protractor example results for " + lang + " on " + (new Date()).toLocaleString() + "\n\n";
116117
if (filter) {
117118
header += ' Filter: ' + filter.toString() + '\n\n';
118119
}
@@ -128,8 +129,14 @@ function findAndRunE2eTests(filter) {
128129
fsExtra.copySync(srcConfig, destConfig);
129130
// get all of the examples under each dir where a pcFilename is found
130131
examplePaths = getExamplePaths(specPath, true);
132+
// Filter by language
133+
examplePaths = examplePaths.filter(function (fn) {
134+
gutil.log('example path: ' + fn + '; matches lang? ' + (fn.match('/'+lang+'$') != null));
135+
return fn.match('/'+lang+'$') != null;
136+
});
131137
if (filter) {
132138
examplePaths = examplePaths.filter(function (fn) {
139+
gutil.log('example path: ' + fn + '; matches? ' + filter + ' ' + (fn.match(filter) != null));
133140
return fn.match(filter) != null;
134141
})
135142
}
@@ -142,7 +149,8 @@ function findAndRunE2eTests(filter) {
142149
var status = { passed: [], failed: [] };
143150
return exeConfigs.reduce(function (promise, combo) {
144151
return promise.then(function () {
145-
return runE2eTests(combo.examplePath, combo.protractorConfigFilename, outputFile).then(function(ok) {
152+
var runTests = lang == 'dart' ? runE2eTestsForDart : runE2eTests;
153+
return runTests(combo.examplePath, combo.protractorConfigFilename, outputFile).then(function(ok) {
146154
var arr = ok ? status.passed : status.failed;
147155
arr.push(combo.examplePath);
148156
})
@@ -184,19 +192,54 @@ function runE2eTests(appDir, protractorConfigFilename, outputFile ) {
184192
});
185193
}
186194

195+
function runE2eTestsForDart(appDir, protractorConfigFilename, outputFile) {
196+
var deployDir = path.resolve(path.join(appDir, 'build/web'));
197+
gutil.log('AppDir for Dart e2e: ' + appDir );
198+
gutil.log('Deploying from: ' + deployDir);
199+
200+
var appRunSpawnInfo = spawnExt('npm', ['run', 'http-server:e2e', deployDir, '-s'], { cwd: EXAMPLES_PATH });
201+
if (!appRunSpawnInfo.proc.pid) {
202+
gutil.log('http-server failed to launch over ' + deployDir);
203+
return false;
204+
}
205+
var pubUpgradeSpawnInfo = spawnExt('pub', ['upgrade'], { cwd: appDir });
206+
207+
return pubUpgradeSpawnInfo.promise.then(function (data) {
208+
return spawnExt('pub', ['build'], { cwd: appDir }).promise;
209+
}).then(function (data) {
210+
// start protractor
211+
var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir
212+
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
213+
var spawnInfo = spawnExt('protractor',
214+
[pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath });
215+
return spawnInfo.promise;
216+
}).then(function (data) {
217+
// kill the app now that protractor has completed.
218+
// Ugh... proc.kill does not work properly on windows with child processes.
219+
// appRun.proc.kill();
220+
treeKill(appRunSpawnInfo.proc.pid);
221+
return !data;
222+
}).fail(function (err) {
223+
// Ugh... proc.kill does not work properly on windows with child processes.
224+
// appRun.proc.kill();
225+
treeKill(appRunSpawnInfo.proc.pid);
226+
return false;
227+
});
228+
}
229+
187230
function reportStatus(status) {
188231
gutil.log('Suites passed:');
189232
status.passed.forEach(function(val) {
190233
gutil.log(' ' + val);
191234
});
192235

193-
gutil.log('Suites failed:');
194-
status.failed.forEach(function(val) {
195-
gutil.log(' ' + val);
196-
});
197-
198236
if (status.failed.length == 0) {
199237
gutil.log('All tests passed');
238+
} else {
239+
gutil.log('Suites failed:');
240+
status.failed.forEach(function (val) {
241+
gutil.log(' ' + val);
242+
});
200243
}
201244
gutil.log('Elapsed time: ' + status.elapsedTime + ' seconds');
202245
}
@@ -206,12 +249,12 @@ function spawnExt(command, args, options) {
206249
var deferred = Q.defer();
207250
var descr = command + " " + args.join(' ');
208251
var proc;
209-
gutil.log('running: ' + descr);
210252
try {
211253
proc = xSpawn.spawn(command, args, options);
212254
} catch(e) {
213255
gutil.log(e);
214256
deferred.reject(e);
257+
gutil.log('failed to run: ' + descr);
215258
return { proc: null, promise: deferred.promise };
216259
}
217260
proc.stdout.on('data', function (data) {
@@ -229,6 +272,7 @@ function spawnExt(command, args, options) {
229272
gutil.log(data.toString());
230273
deferred.reject(data);
231274
});
275+
gutil.log('running: ' + descr);
232276
return { proc: proc, promise: deferred.promise };
233277
}
234278

public/docs/_examples/quickstart/dart/example-config.json

Whitespace-only changes.

public/docs/_examples/toh-5/dart/example-config.json

Whitespace-only changes.

0 commit comments

Comments
 (0)