Skip to content

Commit

Permalink
use TestProcess for better test output on failures and timeouts (#2594)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Jan 10, 2020
1 parent e066b16 commit 3868f9f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion _test/build.dart2js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ targets:
options:
compiler: dart2js
dart2js_args:
- --checked
- --enable-asserts
generate_for:
- web/main.dart
- web/sub/main.dart
Expand Down
1 change: 1 addition & 0 deletions _test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dev_dependencies:
analyzer: ">=0.30.0 <0.39.0"
path: ^1.4.2
test: ^1.6.2
test_process: ^1.0.4
provides_builder:
path: pkgs/provides_builder/

Expand Down
27 changes: 15 additions & 12 deletions _test/test/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';

Directory _generatedDir = Directory(p.join(_toolDir.path, 'generated'));
Directory _toolDir = Directory(p.join('.dart_tool', 'build'));
Expand Down Expand Up @@ -157,13 +158,15 @@ Future<String> nextStdOutLine(String message) =>
_stdOutLines.firstWhere((line) => line.contains(message));

/// Runs tests using the auto build script.
Future<ProcessResult> runTests(
{bool usePrecompiled, List<String> buildArgs, List<String> testArgs}) {
Future<TestProcess> runTests(
{bool usePrecompiled,
List<String> buildArgs,
List<String> testArgs}) async {
return _runTests(_pubBinary, ['run', 'build_runner'],
usePrecompiled: usePrecompiled, buildArgs: buildArgs, testArgs: testArgs);
}

Future<ProcessResult> _runTests(String executable, List<String> scriptArgs,
Future<TestProcess> _runTests(String executable, List<String> scriptArgs,
{bool usePrecompiled,
List<String> buildArgs,
List<String> testArgs}) async {
Expand All @@ -177,10 +180,10 @@ Future<ProcessResult> _runTests(String executable, List<String> scriptArgs,
..addAll(buildArgs ?? [])
..add('--')
..addAll(testArgs);
return Process.run(executable, args);
return TestProcess.start(executable, args);
} else {
var args = ['run', 'test', '--pub-serve', '8081']..addAll(testArgs);
return Process.run(_pubBinary, args);
return TestProcess.start(_pubBinary, args);
}
}

Expand All @@ -190,9 +193,8 @@ Future<void> expectTestsFail(
List<String> testArgs}) async {
var result = await runTests(
usePrecompiled: usePrecompiled, buildArgs: buildArgs, testArgs: testArgs);
printOnFailure('${result.stderr}');
expect(result.stdout, contains('Some tests failed'));
expect(result.exitCode, isNot(0));
expect(result.stdout, emitsThrough(contains('Some tests failed')));
expect(await result.exitCode, isNot(0));
}

Future<void> expectTestsPass(
Expand All @@ -202,12 +204,13 @@ Future<void> expectTestsPass(
List<String> testArgs}) async {
var result = await runTests(
usePrecompiled: usePrecompiled, buildArgs: buildArgs, testArgs: testArgs);
printOnFailure('${result.stderr}');
expect(result.stdout, contains('All tests passed!'));
var allLines = await result.stdout.rest.toList();
expect(allLines, contains(contains('All tests passed!')));
if (expectedNumRan != null) {
expect(result.stdout, contains('+$expectedNumRan'));
expect(result.stdout, isNot(contains('+${expectedNumRan + 1}')));
expect(allLines, contains(contains('+$expectedNumRan')));
expect(allLines, isNot(contains(contains('+${expectedNumRan + 1}'))));
}
expect(await result.exitCode, 0);
}

Future<void> createFile(String path, String contents) async {
Expand Down
9 changes: 4 additions & 5 deletions _test/test/test_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ void main() {
test('Failing tests print mapped stack traces', () async {
var result = await runTests(
testArgs: ['--run-skipped', 'test/hello_world_test.dart']);
printOnFailure(result.stderr.toString());
expect(result.exitCode, isNot(ExitCode.success));
expect(
result.stdout, matches(RegExp(r'hello_world_test.dart [\d]+:[\d]+')));
expect(result.stdout, isNot(contains('.js')));
expect(result.stdout,
emitsThrough(matches(RegExp(r'hello_world_test.dart [\d]+:[\d]+'))));
expect(result.stdout, neverEmits(contains('.js')));
expect(await result.exitCode, isNot(ExitCode.success));
});

group('file edits', () {
Expand Down

0 comments on commit 3868f9f

Please sign in to comment.