2015-02-20 20:44:23 -05:00
|
|
|
var Q = require('q');
|
|
|
|
var glob = require('glob');
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
|
|
|
|
var util = require('./util');
|
|
|
|
|
|
|
|
module.exports = function(gulp, plugins, config) {
|
|
|
|
return function() {
|
2015-06-05 14:06:24 -04:00
|
|
|
if (config.dir) {
|
|
|
|
return run(config.dir);
|
|
|
|
} else {
|
|
|
|
return util.forEachSubDirSequential(config.dest, run);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function run(dir) {
|
|
|
|
var testDir = path.join(dir, 'test');
|
|
|
|
var relativeMasterTestFile = 'test/_all_tests.dart';
|
|
|
|
var testFiles = [].slice.call(glob.sync('**/*.server.spec.dart', {
|
|
|
|
cwd: testDir
|
|
|
|
}));
|
|
|
|
if (testFiles.length == 0) {
|
|
|
|
// No test files found
|
|
|
|
return Q.resolve();
|
|
|
|
}
|
|
|
|
var header = ['library _all_tests;', ''];
|
|
|
|
var main = ['main() {'];
|
|
|
|
testFiles.forEach(function(fileName, index) {
|
|
|
|
header.push('import "' + fileName + '" as test_' + index + ';');
|
|
|
|
main.push(' test_' + index + '.main();');
|
|
|
|
});
|
|
|
|
header.push('');
|
|
|
|
main.push('}');
|
2015-02-20 20:44:23 -05:00
|
|
|
|
2015-06-05 14:06:24 -04:00
|
|
|
var absMasterTestFile = path.join(dir, relativeMasterTestFile);
|
|
|
|
fs.writeFileSync(absMasterTestFile, header.concat(main).join('\n'));
|
2015-02-20 20:44:23 -05:00
|
|
|
|
2015-06-05 14:06:24 -04:00
|
|
|
var defer = Q.defer();
|
|
|
|
var done = defer.makeNodeResolver();
|
2015-08-11 15:53:01 -04:00
|
|
|
console.log('start tests:', dir);
|
2015-06-05 14:06:24 -04:00
|
|
|
util.processToPromise(spawn('dart', ['-c', relativeMasterTestFile], {
|
|
|
|
stdio: 'inherit',
|
|
|
|
cwd: dir
|
|
|
|
})).then(
|
|
|
|
function() { done(); },
|
|
|
|
function(error) { done(error); }
|
2015-02-20 20:44:23 -05:00
|
|
|
);
|
2015-06-05 14:06:24 -04:00
|
|
|
return defer.promise.then(function() {
|
|
|
|
console.log('end tests');
|
|
|
|
});
|
|
|
|
}
|
2015-02-20 20:44:23 -05:00
|
|
|
};
|