chore(test): migrate Dart tests to package:test

Instead of running with karma and the karma-dart shim, run dart
tests directly using the new package:test runner. This migrates
away from package:unittest.

Fixes a couple tests, mostly associated with depending on absolute
URLs or editing the test providers after an injector had already
been created.

Remove karma-dart and associated files. Change gupfiles to run tests
via `pub run test` instead.
This commit is contained in:
Julie Ralph
2016-02-10 16:54:32 -08:00
parent 7455b907d1
commit 5a59e44765
39 changed files with 532 additions and 511 deletions

View File

@ -0,0 +1,21 @@
var path = require('path');
var fs = require('fs');
module.exports = function(dir, files) {
var filename = 'main_test.dart';
var imports = [
'@TestOn("browser")',
'import "package:guinness2/guinness2.dart";'];
var executes = [];
files.forEach(function(match) {
var varName = match.replace(/[\/.]/g, '_');
imports.push('import "' + match + '" as ' + varName +';');
executes.push(' ' + varName + '.main();');
});
var output = imports.join('\n') + '\n\nmain() {\n' + executes.join('\n') + '\n}';
fs.writeFileSync(path.join(dir, filename), output);
return filename;
};

View File

@ -1,7 +1,7 @@
var util = require('./util');
var spawn = require('child_process').spawn;
module.exports = function(gulp, plugins, config, module) {
module.exports = function(gulp, plugins, config) {
return function() {
config.port = config.port || 8080;
var pubMode = config.mode || 'debug';

51
tools/build/pubtest.js Normal file
View File

@ -0,0 +1,51 @@
var util = require('./util');
var spawn = require('child_process').spawn;
var glob = require('glob');
var path = require('path');
var fs = require('fs');
var process = require('process');
var createTestMain = require('./create_dart_test_main.js')
function filterExclusiveTestFiles(files, dir) {
return files.filter(function(file) {
// TODO(juliemr): revisit if readFileSync becomes too slow.
// At the moment, this takes <100ms for all of angular2.
var text = fs.readFileSync(path.join(dir, file));
var iit = text.indexOf('iit(');
var ddescribe = text.indexOf('ddescribe(');
return (iit !== -1 || ddescribe !== -1);
});
}
module.exports = function(config) {
var platform = config.platform || 'dartium';
var pubArgs = ['run', 'test', '-p', platform];
var env = process.env;
var exclusive = false;
if (config.dartiumTmpdir) {
env['PATH'] = env['PATH'] + ':' + config.dartiumTmpdir;
}
testFiles = glob.sync(path.join(config.files), {cwd: config.dir});
if (config.useExclusiveTests) {
var filtered = filterExclusiveTestFiles(testFiles, config.dir);
if (filtered.length) {
exclusive = true;
pubArgs.push('--tags');
pubArgs.push('solo');
testFiles = filtered;
}
}
if (config.bunchFiles && !exclusive) {
var bigFile = createTestMain(config.dir, testFiles);
testFiles = [bigFile];
}
pubArgs = pubArgs.concat(testFiles);
return util.processToPromise(spawn(config.command, pubArgs, {
cwd: config.dir, stdio: 'inherit', env: env
}));
};