Skip to content

Commit

Permalink
Add new timeline modes TimelineMode.always and TimelineMode.reportOnE…
Browse files Browse the repository at this point in the history
…rror

Deprecate TimelineMode.record in favour of TimelineMode.reportOnError
  • Loading branch information
passsy committed Nov 12, 2024
1 parent ac6bb78 commit 2d67cbf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
56 changes: 41 additions & 15 deletions lib/src/timeline/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -185,27 +188,40 @@ class Timeline {
///
/// Prints the timeline to console, as link to a html file or plain text
Future<void> _onPostTest() async {
Future<void> 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.
// Finalize with html report
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;
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions test/timeline/timeline_test_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);',
};
Expand All @@ -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;',
};
Expand Down

0 comments on commit 2d67cbf

Please sign in to comment.