Index: lib/src/runner/load_suite.dart |
diff --git a/lib/src/runner/load_suite.dart b/lib/src/runner/load_suite.dart |
index c43a10062df9887000fa88ab0d024c5092477720..919aa88c69d3c62d985707f2bb443e66dfd3950a 100644 |
--- a/lib/src/runner/load_suite.dart |
+++ b/lib/src/runner/load_suite.dart |
@@ -42,6 +42,9 @@ class LoadSuite extends Suite { |
/// [body] may return either a [Suite] or a [Future] that completes to a |
/// [Suite]. Its return value is forwarded through [suite], although if it |
/// throws an error that will be forwarded through the suite's test. |
+ /// |
+ /// If the the load test is closed before [body] is complete, it will close |
+ /// the suite returned by [body] once it completes. |
factory LoadSuite(String name, body(), {String platform}) { |
var completer = new Completer.sync(); |
return new LoadSuite._(name, () { |
@@ -51,7 +54,13 @@ class LoadSuite extends Suite { |
invoke(() async { |
try { |
var suite = await body(); |
- if (completer.isCompleted) return; |
+ if (completer.isCompleted) { |
+ // If the load test has already been closed, close the suite it |
+ // generated. |
+ suite.close(); |
+ return; |
+ } |
+ |
completer.complete(suite); |
invoker.removeOutstandingCallback(); |
} catch (error, stackTrace) { |
@@ -95,6 +104,21 @@ class LoadSuite extends Suite { |
body) |
], platform: platform); |
+ /// A constructor used by [changeSuite]. |
+ LoadSuite._changeSuite(LoadSuite old, Future<Suite> this.suite) |
+ : super(old.tests, platform: old.platform); |
+ |
+ /// Creates a new [LoadSuite] that's identical to this one, but that |
+ /// transforms [suite] once it's loaded. |
+ /// |
+ /// If [suite] completes to `null`, [change] won't be run. |
+ Suite changeSuite(Suite change(Suite suite)) { |
+ return new LoadSuite._changeSuite(this, suite.then((loadedSuite) { |
+ if (loadedSuite == null) return null; |
+ return change(loadedSuite); |
+ })); |
+ } |
+ |
/// Runs the test and returns the suite. |
/// |
/// Rather than emitting errors through a [LiveTest], this just pipes them |