OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Support for writing Dart unit tests. | 6 * Support for writing Dart unit tests. |
7 * | 7 * |
8 * For information on installing and importing this library, see the | 8 * For information on installing and importing this library, see the |
9 * [unittest package on pub.dartlang.org] | 9 * [unittest package on pub.dartlang.org] |
10 * (http://pub.dartlang.org/packages/unittest). | 10 * (http://pub.dartlang.org/packages/unittest). |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 // Support running on d8 and jsshell which don't support timers. | 756 // Support running on d8 and jsshell which don't support timers. |
757 } | 757 } |
758 } | 758 } |
759 f.whenComplete(() { | 759 f.whenComplete(() { |
760 if (timer != null) timer.cancel(); | 760 if (timer != null) timer.cancel(); |
761 var now = new DateTime.now().millisecondsSinceEpoch; | 761 var now = new DateTime.now().millisecondsSinceEpoch; |
762 if ((now - _lastBreath) >= BREATH_INTERVAL) { | 762 if ((now - _lastBreath) >= BREATH_INTERVAL) { |
763 _lastBreath = now; | 763 _lastBreath = now; |
764 Timer.run(_nextTestCase); | 764 Timer.run(_nextTestCase); |
765 } else { | 765 } else { |
766 runAsync(_nextTestCase); // Schedule the next test. | 766 scheduleMicrotask(_nextTestCase); // Schedule the next test. |
767 } | 767 } |
768 }); | 768 }); |
769 } | 769 } |
770 } | 770 } |
771 | 771 |
772 /** Publish results on the page and notify controller. */ | 772 /** Publish results on the page and notify controller. */ |
773 void _completeTests() { | 773 void _completeTests() { |
774 if (!_initialized) return; | 774 if (!_initialized) return; |
775 int passed = 0; | 775 int passed = 0; |
776 int failed = 0; | 776 int failed = 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 // Hook our async guard into the matcher library. | 810 // Hook our async guard into the matcher library. |
811 wrapAsync = (f, [id]) => expectAsync1(f, id: id); | 811 wrapAsync = (f, [id]) => expectAsync1(f, id: id); |
812 | 812 |
813 _uncaughtErrorMessage = null; | 813 _uncaughtErrorMessage = null; |
814 | 814 |
815 unittestConfiguration.onInit(); | 815 unittestConfiguration.onInit(); |
816 | 816 |
817 if (configAutoStart && _config.autoStart) { | 817 if (configAutoStart && _config.autoStart) { |
818 // Immediately queue the suite up. It will run after a timeout (i.e. after | 818 // Immediately queue the suite up. It will run after a timeout (i.e. after |
819 // main() has returned). | 819 // main() has returned). |
820 runAsync(runTests); | 820 scheduleMicrotask(runTests); |
821 } | 821 } |
822 } | 822 } |
823 | 823 |
824 /** Select a solo test by ID. */ | 824 /** Select a solo test by ID. */ |
825 void setSoloTest(int id) => | 825 void setSoloTest(int id) => |
826 _testCases.retainWhere((t) => t.id == id); | 826 _testCases.retainWhere((t) => t.id == id); |
827 | 827 |
828 /** Enable/disable a test by ID. */ | 828 /** Enable/disable a test by ID. */ |
829 void _setTestEnabledState(int testId, bool state) { | 829 void _setTestEnabledState(int testId, bool state) { |
830 // Try fast path first. | 830 // Try fast path first. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 | 880 |
881 if (!filterStacks) return trace; | 881 if (!filterStacks) return trace; |
882 | 882 |
883 // Format the stack trace by removing everything above TestCase._runTest, | 883 // Format the stack trace by removing everything above TestCase._runTest, |
884 // which is usually going to be irrelevant. Also fold together unittest and | 884 // which is usually going to be irrelevant. Also fold together unittest and |
885 // core library calls so only the function the user called is visible. | 885 // core library calls so only the function the user called is visible. |
886 return new Trace(trace.frames.takeWhile((frame) { | 886 return new Trace(trace.frames.takeWhile((frame) { |
887 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 887 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
888 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 888 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
889 } | 889 } |
OLD | NEW |