Fix dart-json parsing broken by print message

Print message related to suite, instead of a specific test, would break parsing - it would expect test object to be present in dictionary but there would be none.
This fix adds necessary check and messages not related to tracked tests will be ignored.
This commit is contained in:
Michal Dorner 2021-05-13 21:48:55 +02:00
parent cbdb218336
commit dcaab46b46
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
3 changed files with 6 additions and 3 deletions

View file

@ -4,6 +4,7 @@
{"suite":{"id":2,"platform":"vm","path":"test\\second_test.dart"},"type":"suite","time":11} {"suite":{"id":2,"platform":"vm","path":"test\\second_test.dart"},"type":"suite","time":11}
{"test":{"id":3,"name":"loading test\\second_test.dart","suiteID":2,"groupIDs":[],"metadata":{"skip":false,"skipReason":null},"line":null,"column":null,"url":null},"type":"testStart","time":11} {"test":{"id":3,"name":"loading test\\second_test.dart","suiteID":2,"groupIDs":[],"metadata":{"skip":false,"skipReason":null},"line":null,"column":null,"url":null},"type":"testStart","time":11}
{"count":2,"type":"allSuites","time":11} {"count":2,"type":"allSuites","time":11}
{"testID":1,"messageType":"print","message":"Hello from the test","type":"print","time":3828}
{"testID":3,"result":"success","skipped":false,"hidden":true,"type":"testDone","time":3649} {"testID":3,"result":"success","skipped":false,"hidden":true,"type":"testDone","time":3649}
{"group":{"id":4,"suiteID":2,"parentID":null,"name":null,"metadata":{"skip":false,"skipReason":null},"testCount":2,"line":null,"column":null,"url":null},"type":"group","time":3654} {"group":{"id":4,"suiteID":2,"parentID":null,"name":null,"metadata":{"skip":false,"skipReason":null},"testCount":2,"line":null,"column":null,"url":null},"type":"group","time":3654}
{"test":{"id":5,"name":"Timeout test","suiteID":2,"groupIDs":[4],"metadata":{"skip":false,"skipReason":null},"line":5,"column":3,"url":"file:///C:/Users/Michal/Workspace/dorny/test-check/reports/dart/test/second_test.dart"},"type":"testStart","time":3655} {"test":{"id":5,"name":"Timeout test","suiteID":2,"groupIDs":[4],"metadata":{"skip":false,"skipReason":null},"line":5,"column":3,"url":"file:///C:/Users/Michal/Workspace/dorny/test-check/reports/dart/test/second_test.dart"},"type":"testStart","time":3655}

View file

@ -24,4 +24,6 @@ void main() {
throw Exception('Some error'); throw Exception('Some error');
}); });
}); });
print('Hello from the test');
} }

View file

@ -114,11 +114,11 @@ export class DartJsonParser implements TestParser {
const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]] const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]]
group.tests.push(test) group.tests.push(test)
tests[evt.test.id] = test tests[evt.test.id] = test
} else if (isTestDoneEvent(evt) && !evt.hidden) { } else if (isTestDoneEvent(evt) && !evt.hidden && tests[evt.testID]) {
tests[evt.testID].testDone = evt tests[evt.testID].testDone = evt
} else if (isErrorEvent(evt)) { } else if (isErrorEvent(evt) && tests[evt.testID]) {
tests[evt.testID].error = evt tests[evt.testID].error = evt
} else if (isMessageEvent(evt)) { } else if (isMessageEvent(evt) && tests[evt.testID]) {
tests[evt.testID].print.push(evt) tests[evt.testID].print.push(evt)
} else if (isDoneEvent(evt)) { } else if (isDoneEvent(evt)) {
success = evt.success success = evt.success