Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/src/tasks/test/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class TestCli extends TaskCli {
..addOption('name',
abbr: 'n',
help:
'A substring of the name of the test to run.\nRegular expression syntax is supported.');
'A substring of the name of the test to run.\nRegular expression syntax is supported.')
..addOption('web-compiler',
abbr: 'w', help: ' The JavaScript compiler to use to serve the tests.');

final String command = 'test';

Expand Down Expand Up @@ -118,6 +120,8 @@ class TestCli extends TaskCli {
// CLI user can filter tests by name.
bool testNamed = parsedArgs['name'] != null;

bool compilerSpecified = parsedArgs['web-compiler'] != null;

if (!individualTestsSpecified && !unit && !integration && !functional) {
return new CliResult.fail(
'No tests were selected. Include at least one of --unit, '
Expand Down Expand Up @@ -169,8 +173,13 @@ class TestCli extends TaskCli {

if (!isPubServeRunning) {
// Start `pub serve` on the `test` directory
var additionalArgs = ['test'];
if (compilerSpecified) {
additionalArgs.add('--web-compiler=${parsedArgs['web-compiler']}');
}

pubServeTask =
startPubServe(port: pubServePort, additionalArgs: ['test']);
startPubServe(port: pubServePort, additionalArgs: additionalArgs);

var startupLogFinished = new Completer();
reporter.logGroup(pubServeTask.command,
Expand Down
40 changes: 33 additions & 7 deletions test/integration/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Future<int> runTests(String projectPath,
List<String> files,
String testName: '',
bool runCustomPubServe: false,
int pubServePort: 56090}) async {
int pubServePort: 56090,
String webCompiler}) async {
await Process.run('pub', ['get'], workingDirectory: projectPath);

List args = ['run', 'dart_dev', 'test', '--no-color'];
Expand Down Expand Up @@ -77,24 +78,44 @@ Future<int> runTests(String projectPath,
}

args.addAll(files ?? <String>[]);

String webCompilerArg;

if (webCompiler != null) {
webCompilerArg = '--web-compiler=${webCompiler}';
args.add(webCompilerArg);
}

TaskProcess process =
new TaskProcess('pub', args, workingDirectory: projectPath);

var numTestsRun = -1;
var webCompilerSpecified = false;

process.stdout.listen((output) {
if (numTestsPassedPattern.hasMatch(output)) {
numTestsRun =
int.parse(numTestsPassedPattern.firstMatch(output).group(1));
}
if (webCompiler != null && output.contains(webCompilerArg)) {
webCompilerSpecified = true;
}
});

await process.done;
if ((await process.exitCode) != 0)
throw new TestFailure('Expected test to pass.');

String lastLine = await process.stdout.last;

if (pubServeProcess != null) {
pubServeProcess.kill();
}

var numTestsRun = -1;
if (numTestsPassedPattern.hasMatch(lastLine)) {
numTestsRun =
int.parse(numTestsPassedPattern.firstMatch(lastLine).group(1));
if (webCompiler != null) {
expect(webCompilerSpecified, isTrue,
reason:
'$webCompiler was not approriately applied to the pub serve task');
}

return numTestsRun;
}

Expand Down Expand Up @@ -177,5 +198,10 @@ void main() {
expect(runTests(projectWithPassingTests, testName: 'non-existent test'),
throwsA(new isInstanceOf<TestFailure>()));
});

test('should allow you to specify a web-compiler', () async {
expect(await runTests(projectThatNeedsPubServe, webCompiler: 'dartdevc'),
equals(1));
});
});
}