Skip to content

Commit 965e355

Browse files
Associate printOnFailure messages with the failing test (#1751)
1 parent aba7de5 commit 965e355

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.21.5-dev
22

3+
* Fix `printOnFailure` output to be associated with the correct test.
34
* Migrate all dom interactions to static interop.
45

56
## 1.21.4

pkgs/test_api/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 0.4.13-dev
22

3-
* Internal cleanup.
3+
* Fix `printOnFailure` output to be associated with the correct test.
44

55
## 0.4.12
66

pkgs/test_api/lib/src/backend/invoker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class Invoker {
315315
void printOnFailure(String message) {
316316
message = message.trim();
317317
if (liveTest.state.result.isFailing) {
318-
print('\n$message');
318+
_print('\n$message');
319319
} else {
320320
_printsOnFailure.add(message);
321321
}
@@ -350,7 +350,7 @@ class Invoker {
350350
zone.run(() => _outstandingCallbacks.complete());
351351

352352
if (_printsOnFailure.isNotEmpty) {
353-
print(_printsOnFailure.join('\n\n'));
353+
_print(_printsOnFailure.join('\n\n'));
354354
_printsOnFailure.clear();
355355
}
356356

pkgs/test_api/test/backend/invoker_test.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -541,27 +541,30 @@ void main() {
541541
});
542542

543543
group('printOnFailure:', () {
544-
test("doesn't print anything if the test succeeds", () {
545-
expect(() async {
546-
var liveTest = _localTest(() {
547-
Invoker.current!.printOnFailure('only on failure');
548-
}).load(suite);
549-
liveTest.onError.listen(expectAsync1((_) {}, count: 0));
550-
551-
await liveTest.run();
552-
}, prints(isEmpty));
544+
test("doesn't print anything if the test succeeds", () async {
545+
var liveTest = _localTest(() {
546+
Invoker.current!.printOnFailure('only on failure');
547+
}).load(suite);
548+
liveTest.onError.listen(expectAsync1((_) {}, count: 0));
549+
550+
liveTest.onMessage.listen(expectAsync1((_) {}, count: 0));
551+
552+
await liveTest.run();
553553
});
554554

555-
test('prints if the test fails', () {
556-
expect(() async {
557-
var liveTest = _localTest(() {
558-
Invoker.current!.printOnFailure('only on failure');
559-
expect(true, isFalse);
560-
}).load(suite);
561-
liveTest.onError.listen(expectAsync1((_) {}, count: 1));
555+
test('prints if the test fails', () async {
556+
var liveTest = _localTest(() {
557+
Invoker.current!.printOnFailure('only on failure');
558+
expect(true, isFalse);
559+
}).load(suite);
560+
liveTest.onError.listen(expectAsync1((_) {}, count: 1));
562561

563-
await liveTest.run();
564-
}, prints('only on failure\n'));
562+
liveTest.onMessage.listen(expectAsync1((message) {
563+
expect(message.type, equals(MessageType.print));
564+
expect(message.text, equals('only on failure'));
565+
}, count: 1));
566+
567+
await liveTest.run();
565568
});
566569
});
567570
}

0 commit comments

Comments
 (0)