diff --git a/lib/src/backend/declarer.dart b/lib/src/backend/declarer.dart index 5c59eac84..72e4d317a 100644 --- a/lib/src/backend/declarer.dart +++ b/lib/src/backend/declarer.dart @@ -78,16 +78,16 @@ class Declarer { testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform, tags: tags)); - _entries.add(new LocalTest(_prefix(name), metadata, () { + _entries.add(new LocalTest(_prefix(name), metadata, () async { // TODO(nweiz): It might be useful to throw an error here if a test starts // running while other tests from the same declarer are also running, // since they might share closurized state. - // TODO(nweiz): Use async/await here once issue 23497 has been fixed in - // two stable versions. - return Invoker.current.waitForOutstandingCallbacks(() { - return _runSetUps().then((_) => body()); - }).then((_) => _runTearDowns()); + await Invoker.current.waitForOutstandingCallbacks(() async { + await _runSetUps(); + await body(); + }); + await _runTearDowns(); })); } @@ -161,16 +161,9 @@ class Declarer { /// /// If no set-up functions are declared, this returns a [Future] that /// completes immediately. - Future _runSetUps() { - // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two - // stable versions. - if (_parent != null) { - return _parent._runSetUps().then((_) { - return Future.forEach(_setUps, (setUp) => setUp()); - }); - } - - return Future.forEach(_setUps, (setUp) => setUp()); + Future _runSetUps() async { + if (_parent != null) await _parent._runSetUps(); + await Future.forEach(_setUps, (setUp) => setUp()); } /// Run the tear-up functions for this and any parent groups. diff --git a/lib/src/backend/invoker.dart b/lib/src/backend/invoker.dart index 8ff860ea6..9644d847f 100644 --- a/lib/src/backend/invoker.dart +++ b/lib/src/backend/invoker.dart @@ -178,12 +178,11 @@ class Invoker { var zone; var counter = new OutstandingCallbackCounter(); runZoned(() { - // TODO(nweiz): Use async/await here once issue 23497 has been fixed in - // two stable versions. - runZoned(() { + runZoned(() async { zone = Zone.current; _outstandingCallbackZones.add(zone); - new Future.sync(fn).then((_) => counter.removeOutstandingCallback()); + await fn(); + counter.removeOutstandingCallback(); }, onError: _handleError); }, zoneValues: { _counterKey: counter @@ -260,10 +259,8 @@ class Invoker { var outstandingCallbacksForBody = new OutstandingCallbackCounter(); - // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two - // stable versions. Chain.capture(() { - runZonedWithValues(() { + runZonedWithValues(() async { _invokerZone = Zone.current; _outstandingCallbackZones.add(Zone.current); @@ -276,15 +273,15 @@ class Invoker { new Future(_test._body) .then((_) => removeOutstandingCallback()); - _outstandingCallbacks.noOutstandingCallbacks.then((_) { - if (_timeoutTimer != null) _timeoutTimer.cancel(); - _controller.setState( - new State(Status.complete, liveTest.state.result)); + await _outstandingCallbacks.noOutstandingCallbacks; + if (_timeoutTimer != null) _timeoutTimer.cancel(); - // Use [Timer.run] here to avoid starving the DOM or other - // non-microtask events. - Timer.run(_controller.completer.complete); - }); + _controller.setState( + new State(Status.complete, liveTest.state.result)); + + // Use [Timer.run] here to avoid starving the DOM or other + // non-microtask events. + Timer.run(_controller.completer.complete); }, zoneValues: { #test.invoker: this, // Use the invoker as a key so that multiple invokers can have different diff --git a/pubspec.yaml b/pubspec.yaml index 94f8a657b..23ac55e9c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ author: Dart Team description: A library for writing dart unit tests. homepage: https://github.com/dart-lang/test environment: - sdk: '>=1.11.0 <1.16.0' + sdk: '>=1.13.0 <1.16.0' dependencies: analyzer: '>=0.23.0 <0.28.0' args: '>=0.12.1 <0.14.0'