Chromium Code Reviews| Index: lib/src/runner/reporter/json.dart |
| diff --git a/lib/src/runner/reporter/json.dart b/lib/src/runner/reporter/json.dart |
| index a3166a573fef87a68a1f462f686839677f76984f..a9181fada955d0fe9bb0556b44d9b3666cd54708 100644 |
| --- a/lib/src/runner/reporter/json.dart |
| +++ b/lib/src/runner/reporter/json.dart |
| @@ -6,6 +6,7 @@ import 'dart:async'; |
| import 'dart:convert'; |
| import '../../backend/group.dart'; |
| +import '../../backend/group_entry.dart'; |
| import '../../backend/live_test.dart'; |
| import '../../backend/metadata.dart'; |
| import '../../backend/suite.dart'; |
| @@ -21,6 +22,9 @@ class JsonReporter implements Reporter { |
| /// Whether to use verbose stack traces. |
| final bool _verboseTrace; |
| + /// Whether to emit location information for JS tests. |
| + final bool _jsLocations; |
| + |
| /// The engine used to run the tests. |
| final Engine _engine; |
| @@ -53,13 +57,19 @@ class JsonReporter implements Reporter { |
| /// Watches the tests run by [engine] and prints their results as JSON. |
| /// |
| - /// If [verboseTrace] is `true`, this will print core library frames. |
| - static JsonReporter watch(Engine engine, {bool verboseTrace: false}) { |
| - return new JsonReporter._(engine, verboseTrace: verboseTrace); |
| + /// If [verboseTrace] is `true`, this will print core library frames. If |
| + /// [jsLocations] is `false`, this will not emit location information for JS |
| + /// tests. |
| + static JsonReporter watch(Engine engine, {bool verboseTrace: false, |
| + bool jsLocations: true}) { |
| + return new JsonReporter._(engine, |
| + verboseTrace: verboseTrace, jsLocations: jsLocations); |
| } |
| - JsonReporter._(this._engine, {bool verboseTrace: false}) |
| - : _verboseTrace = verboseTrace { |
| + JsonReporter._(this._engine, {bool verboseTrace: false, |
| + bool jsLocations: true}) |
| + : _verboseTrace = verboseTrace, |
| + _jsLocations = jsLocations { |
| _subscriptions.add(_engine.onTestStarted.listen(_onTestStarted)); |
| /// Convert the future to a stream so that the subscription can be paused or |
| @@ -120,18 +130,18 @@ class JsonReporter implements Reporter { |
| // unnecessary clutter. |
| var groupIDs = liveTest.suite is LoadSuite |
| ? [] |
| - : _idsForGroups(liveTest.groups, suiteID); |
| + : _idsForGroups(liveTest.groups, liveTest.suite); |
| var id = _nextID++; |
| _liveTestIDs[liveTest] = id; |
| _emit("testStart", { |
| - "test": { |
| + "test": _addFrameInfo({ |
| "id": id, |
| "name": liveTest.test.name, |
| "suiteID": suiteID, |
| "groupIDs": groupIDs, |
| "metadata": _serializeMetadata(liveTest.test.metadata) |
| - } |
| + }, liveTest.test, liveTest.suite.platform) |
| }); |
| /// Convert the future to a stream so that the subscription can be paused or |
| @@ -183,7 +193,7 @@ class JsonReporter implements Reporter { |
| /// |
| /// If a group doesn't have an ID yet, this assigns one and emits a new event |
| /// for that group. |
| - List<int> _idsForGroups(Iterable<Group> groups, int suiteID) { |
| + List<int> _idsForGroups(Iterable<Group> groups, Suite suite) { |
| int parentID; |
| return groups.map((group) { |
| if (_groupIDs.containsKey(group)) { |
| @@ -195,14 +205,14 @@ class JsonReporter implements Reporter { |
| _groupIDs[group] = id; |
| _emit("group", { |
| - "group": { |
| + "group": _addFrameInfo({ |
| "id": id, |
| - "suiteID": suiteID, |
| + "suiteID": _idForSuite(suite), |
| "parentID": parentID, |
| "name": group.name, |
| "metadata": _serializeMetadata(group.metadata), |
| "testCount": group.testCount |
| - } |
| + }, group, suite.platform) |
| }); |
| parentID = id; |
| return id; |
| @@ -249,4 +259,19 @@ class JsonReporter implements Reporter { |
| attributes["time"] = _stopwatch.elapsed.inMilliseconds; |
| print(JSON.encode(attributes)); |
| } |
| + |
| + /// Modifies [map] to include line, column, and URL information from the first |
| + /// frame of [entry.trace]. |
| + /// |
| + /// Returns [map]. |
| + Map<String, dynamic> _addFrameInfo(Map<String, dynamic> map, |
| + GroupEntry entry, TestPlatform platform) { |
|
kevmoo
2016/06/15 19:50:38
no import for `TestPlatform` class
nweiz
2016/06/15 20:35:39
Done.
|
| + var frame = entry.trace?.frames?.first; |
| + if (!_jsLocations && platform.isJS) frame = null; |
| + |
| + map["line"] = frame?.line; |
| + map["column"] = frame?.column; |
| + map["url"] = frame?.uri?.toString(); |
| + return map; |
| + } |
| } |