From 2d67cbf75fd0a0724da9071fb68bb862e507a03c Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Tue, 12 Nov 2024 19:55:28 +0100 Subject: [PATCH] Add new timeline modes TimelineMode.always and TimelineMode.reportOnError Deprecate TimelineMode.record in favour of TimelineMode.reportOnError --- lib/src/timeline/timeline.dart | 56 ++++++++++++++++++------- test/timeline/timeline_test_shared.dart | 7 ++++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/src/timeline/timeline.dart b/lib/src/timeline/timeline.dart index 5ddad756..54953b5f 100644 --- a/lib/src/timeline/timeline.dart +++ b/lib/src/timeline/timeline.dart @@ -115,6 +115,9 @@ class Timeline { switch (value) { TimelineMode.live => 'πŸ”΄ - Live! Shows all timeline events as they happen', + TimelineMode.reportOnError => + 'πŸ”΄ - Shows the timeline when the test fails', + TimelineMode.always => 'πŸ”΄ - Always shows the timeline', TimelineMode.record => 'πŸ”΄ - Recording, but only showing on test failure', TimelineMode.off => '⏸︎ - Timeline recording is off', @@ -185,6 +188,20 @@ class Timeline { /// /// Prints the timeline to console, as link to a html file or plain text Future _onPostTest() async { + Future reportOnError() async { + if (!test.state.result.isPassing) { + // ignore: avoid_print + print('Test failed, generating timeline report'); + await processPendingScreenshots(); + if (isCI) { + // best for CI, prints the full timeline and doesn't require archiving the html timeline file + printToConsole(); + } + // best for humans + printHTML(); + } + } + switch (mode) { case TimelineMode.live: // during live mode the events are written directly to the console. @@ -192,20 +209,19 @@ class Timeline { await processPendingScreenshots(); printHTML(); case TimelineMode.record: - if (!test.state.result.isPassing) { - // ignore: avoid_print - print('Test failed, generating timeline report'); - await processPendingScreenshots(); - if (isCI) { - // best for CI, prints the full timeline and doesn't require archiving the html timeline file - printToConsole(); - } - // best for humans - printHTML(); - } else { - // do nothing - break; + await reportOnError(); + case TimelineMode.reportOnError: + await reportOnError(); + case TimelineMode.always: + // ignore: avoid_print + print('Generating timeline report'); + await processPendingScreenshots(); + if (isCI) { + // best for CI, prints the full timeline and doesn't require archiving the html timeline file + printToConsole(); } + // best for humans + printHTML(); case TimelineMode.off: // do nothing break; @@ -278,13 +294,23 @@ class TimelineEvent { /// - [TimelineMode.record] - The timeline is recording but not printing events unless the test fails. /// - [TimelineMode.off] - The timeline is not recording. enum TimelineMode { - /// The timeline is recording and printing events as they happen. + /// The timeline is recording and printing events to the console as they happen. + /// The timeline is also generated at the end of the test. live, + /// Always prints the timeline at the end of the test + always, + + /// In case the test fails, the timeline is generated at the end of the test. + reportOnError, + /// The timeline is recording but not printing events unless the test fails. + /// + /// Deprecated: It's the same as `reportOnError` but the new name is more descriptive. + @Deprecated('Use reportOnError') record, - /// The timeline is not recording. + /// No events will be recorded, the timeline is not generated after the test off; } diff --git a/test/timeline/timeline_test_shared.dart b/test/timeline/timeline_test_shared.dart index a86bae69..1504e6b1 100644 --- a/test/timeline/timeline_test_shared.dart +++ b/test/timeline/timeline_test_shared.dart @@ -10,8 +10,12 @@ String localTimelineInitiator(TimelineMode timelineMode) { return switch (timelineMode) { TimelineMode.live => 'timeline.mode = TimelineMode.live;\nexpect(timeline.mode, TimelineMode.live);', + TimelineMode.always => + 'timeline.mode = TimelineMode.always;\nexpect(timeline.mode, TimelineMode.always);', TimelineMode.record => 'timeline.mode = TimelineMode.record;\nexpect(timeline.mode, TimelineMode.record);', + TimelineMode.reportOnError => + 'timeline.mode = TimelineMode.reportOnError;\nexpect(timeline.mode, TimelineMode.reportOnError);', TimelineMode.off => 'timeline.mode = TimelineMode.off;\nexpect(timeline.mode, TimelineMode.off);', }; @@ -20,6 +24,9 @@ String localTimelineInitiator(TimelineMode timelineMode) { String globalTimelineInitiator(TimelineMode timelineMode) { return switch (timelineMode) { TimelineMode.live => 'globalTimelineMode = TimelineMode.live;', + TimelineMode.always => 'globalTimelineMode = TimelineMode.always;', + TimelineMode.reportOnError => + 'globalTimelineMode = TimelineMode.reportOnError;', TimelineMode.record => 'globalTimelineMode = TimelineMode.record;', TimelineMode.off => 'globalTimelineMode = TimelineMode.off;', };