| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:stream_channel/stream_channel.dart'; | 7 import 'package:stream_channel/stream_channel.dart'; |
| 8 | 8 |
| 9 import '../backend/declarer.dart'; | 9 import '../backend/declarer.dart'; |
| 10 import '../backend/group.dart'; | 10 import '../backend/group.dart'; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 /// Serializes [group] into a JSON-safe map. | 118 /// Serializes [group] into a JSON-safe map. |
| 119 /// | 119 /// |
| 120 /// [parents] lists the groups that contain [group]. | 120 /// [parents] lists the groups that contain [group]. |
| 121 Map _serializeGroup(MultiChannel channel, Group group, | 121 Map _serializeGroup(MultiChannel channel, Group group, |
| 122 Iterable<Group> parents) { | 122 Iterable<Group> parents) { |
| 123 parents = parents.toList()..add(group); | 123 parents = parents.toList()..add(group); |
| 124 return { | 124 return { |
| 125 "type": "group", | 125 "type": "group", |
| 126 "name": group.name, | 126 "name": group.name, |
| 127 "metadata": group.metadata.serialize(), | 127 "metadata": group.metadata.serialize(), |
| 128 "trace": group.trace?.toString(), |
| 128 "setUpAll": _serializeTest(channel, group.setUpAll, parents), | 129 "setUpAll": _serializeTest(channel, group.setUpAll, parents), |
| 129 "tearDownAll": _serializeTest(channel, group.tearDownAll, parents), | 130 "tearDownAll": _serializeTest(channel, group.tearDownAll, parents), |
| 130 "entries": group.entries.map((entry) { | 131 "entries": group.entries.map((entry) { |
| 131 return entry is Group | 132 return entry is Group |
| 132 ? _serializeGroup(channel, entry, parents) | 133 ? _serializeGroup(channel, entry, parents) |
| 133 : _serializeTest(channel, entry, parents); | 134 : _serializeTest(channel, entry, parents); |
| 134 }).toList() | 135 }).toList() |
| 135 }; | 136 }; |
| 136 } | 137 } |
| 137 | 138 |
| 138 /// Serializes [test] into a JSON-safe map. | 139 /// Serializes [test] into a JSON-safe map. |
| 139 /// | 140 /// |
| 140 /// [groups] lists the groups that contain [test]. Returns `null` if [test] | 141 /// [groups] lists the groups that contain [test]. Returns `null` if [test] |
| 141 /// is `null`. | 142 /// is `null`. |
| 142 Map _serializeTest(MultiChannel channel, Test test, Iterable<Group> groups) { | 143 Map _serializeTest(MultiChannel channel, Test test, Iterable<Group> groups) { |
| 143 if (test == null) return null; | 144 if (test == null) return null; |
| 144 | 145 |
| 145 var testChannel = channel.virtualChannel(); | 146 var testChannel = channel.virtualChannel(); |
| 146 testChannel.stream.listen((message) { | 147 testChannel.stream.listen((message) { |
| 147 assert(message['command'] == 'run'); | 148 assert(message['command'] == 'run'); |
| 148 _runLiveTest( | 149 _runLiveTest( |
| 149 test.load(_suite, groups: groups), | 150 test.load(_suite, groups: groups), |
| 150 channel.virtualChannel(message['channel'])); | 151 channel.virtualChannel(message['channel'])); |
| 151 }); | 152 }); |
| 152 | 153 |
| 153 return { | 154 return { |
| 154 "type": "test", | 155 "type": "test", |
| 155 "name": test.name, | 156 "name": test.name, |
| 156 "metadata": test.metadata.serialize(), | 157 "metadata": test.metadata.serialize(), |
| 158 "trace": test.trace?.toString(), |
| 157 "channel": testChannel.id | 159 "channel": testChannel.id |
| 158 }; | 160 }; |
| 159 } | 161 } |
| 160 | 162 |
| 161 /// Runs [liveTest] and sends the results across [channel]. | 163 /// Runs [liveTest] and sends the results across [channel]. |
| 162 void _runLiveTest(LiveTest liveTest, MultiChannel channel) { | 164 void _runLiveTest(LiveTest liveTest, MultiChannel channel) { |
| 163 channel.stream.listen((message) { | 165 channel.stream.listen((message) { |
| 164 assert(message['command'] == 'close'); | 166 assert(message['command'] == 'close'); |
| 165 liveTest.close(); | 167 liveTest.close(); |
| 166 }); | 168 }); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 182 }); | 184 }); |
| 183 | 185 |
| 184 liveTest.onPrint.listen((line) { | 186 liveTest.onPrint.listen((line) { |
| 185 if (_printZone != null) _printZone.print(line); | 187 if (_printZone != null) _printZone.print(line); |
| 186 channel.sink.add({"type": "print", "line": line}); | 188 channel.sink.add({"type": "print", "line": line}); |
| 187 }); | 189 }); |
| 188 | 190 |
| 189 liveTest.run().then((_) => channel.sink.add({"type": "complete"})); | 191 liveTest.run().then((_) => channel.sink.add({"type": "complete"})); |
| 190 } | 192 } |
| 191 } | 193 } |
| OLD | NEW |