@@ -3,7 +3,7 @@ import 'package:logger/logger.dart';
33
44import 'monochrome_printer.dart' ;
55
6- class WidgetStdoutReporter extends Reporter {
6+ class WidgetStdoutReporter implements FullReporter {
77 /// https://talyian.github.io/ansicolors/
88 final AnsiColor neutralColor = AnsiColor .none ();
99 final AnsiColor debugColor = AnsiColor .fg (7 ); // gray
@@ -15,92 +15,99 @@ class WidgetStdoutReporter extends Reporter {
1515 final logger = Logger (printer: MonochromePrinter ());
1616
1717 @override
18- Future <void > onScenarioStarted (StartedMessage message) async {
19- logger.i (coolColor ('\n ${'-' * 100 }\n ' ));
20- logger.i (coolColor (
21- '${DateTime .now ()} - Running scenario: ${message .name + _getContext (message .context )}' ));
22- }
18+ Future <void > dispose () async {}
2319
2420 @override
25- Future <void > onScenarioFinished (ScenarioFinishedMessage message) async {
26- var scenarioColor = message.passed ? passColor : failColor;
27- var scenarioStatus = message.passed ? 'PASSED' : 'FAILED' ;
28- logger.i ('${scenarioColor (scenarioStatus )}: Scenario ${message .name }' );
29- }
21+ ReportActionHandler <FeatureMessage > get feature => ReportActionHandler ();
3022
3123 @override
32- Future <void > onStepFinished (StepFinishedMessage message) async {
33- var stepColor = message.result.result == StepExecutionResult .pass
34- ? passColor
35- : failColor;
36- String printMessage;
37- if (message.result is ErroredStepResult ) {
38- var errorMessage = (message.result as ErroredStepResult );
39- printMessage =
40- failColor ('${errorMessage .exception }\n ${errorMessage .stackTrace }' );
41- } else {
42- printMessage = [
43- stepColor (' ' ),
44- stepColor (_getStatePrefixIcon (message.result.result)),
45- stepColor (message.name),
46- neutralColor (_getExecutionDuration (message.result)),
47- stepColor (_getReasonMessage (message.result)),
48- stepColor (_getErrorMessage (message.result))
49- ].join ((' ' )).trimRight ();
50- }
51- logger.i (printMessage);
52-
53- // TODO adapter à cette classe
54- // if (message.attachments.isNotEmpty) {
55- // message.attachments.forEach(
56- // (attachment) {
57- // var attachment2 = attachment;
58- // printMessageLine(
59- // [
60- // ' ',
61- // 'Attachment',
62- // '(${attachment2.mimeType})${attachment.mimeType == 'text/plain' ? ': ${attachment.data}' : ''}'
63- // ].join((' ')).trimRight(),
64- // StdoutReporter.RESET_COLOR,
65- // );
66- // },
67- // );
68- // }
69- }
24+ Future <void > message (String message, MessageLevel level) async {}
7025
71- String _getReasonMessage (StepResult stepResult) {
72- if (stepResult.resultReason != null &&
73- stepResult.resultReason! .isNotEmpty) {
74- return '\n ${stepResult .resultReason }' ;
75- } else {
76- return '' ;
77- }
78- }
26+ @override
27+ Future <void > onException (Object exception, StackTrace stackTrace) async {}
7928
80- String _getErrorMessage (StepResult stepResult) {
81- if (stepResult is ErroredStepResult ) {
82- return '\n ${stepResult .exception }\n ${stepResult .stackTrace }' ;
83- } else {
84- return '' ;
85- }
86- }
29+ @override
30+ ReportActionHandler <ScenarioMessage > get scenario => ReportActionHandler (
31+ onStarted: ([message]) async {
32+ logger.i (coolColor ("\n ${"-" * 100 }\n " ));
33+ if (message == null ) {
34+ logger.i (failColor ('Cannot get scenario information' ));
35+ } else {
36+ logger.i (coolColor (
37+ '${DateTime .now ()} - Running scenario: ${message .name + _getContext (message .context )}' ));
38+ }
39+ },
40+ onFinished: ([message]) async {
41+ if (message == null ) {
42+ logger.i (failColor ('Cannot get scenario information' ));
43+ } else {
44+ var scenarioColor = message.hasPassed ? passColor : failColor;
45+ var scenarioStatus = message.hasPassed ? "PASSED" : "FAILED" ;
46+ logger.i (
47+ "${scenarioColor (scenarioStatus )}: Scenario ${message .name }" );
48+ }
49+ },
50+ );
8751
88- String _getContext (RunnableDebugInformation context) {
89- return neutralColor (
90- '\t # ${_getFeatureFilePath (context )}:${context .lineNumber }' );
91- }
52+ @override
53+ ReportActionHandler <StepMessage > get step => ReportActionHandler (
54+ onFinished: ([message]) async {
55+ if (message == null ) {
56+ logger.i (failColor ('Cannot get scenario information' ));
57+ } else {
58+ if (message.result == null ) {
59+ logger.i (failColor ('Cannot get result scenario information' ));
60+ } else {
61+ var stepColor =
62+ message.result! .result == StepExecutionResult .passed
63+ ? passColor
64+ : failColor;
65+ String printMessage;
66+ if (message.result is ErroredStepResult ) {
67+ var errorMessage = (message.result as ErroredStepResult );
68+ printMessage = failColor (
69+ '${errorMessage .exception }\n ${errorMessage .stackTrace }' );
70+ } else {
71+ printMessage = [
72+ stepColor (' ' ),
73+ stepColor (_getStatePrefixIcon (message.result! .result)),
74+ stepColor (message.name),
75+ neutralColor (_getExecutionDuration (message.result! )),
76+ stepColor (_getReasonMessage (message.result! )),
77+ stepColor (_getErrorMessage (message.result! ))
78+ ].join ((' ' )).trimRight ();
79+ }
80+ logger.i (printMessage);
81+ }
82+ }
83+ },
84+ );
9285
93- String _getFeatureFilePath (RunnableDebugInformation context) {
94- return context.filePath.replaceAll (RegExp (r'\.\\' ), '' );
95- }
86+ @override
87+ ReportActionHandler <TestMessage > get test => ReportActionHandler ();
9688
97- String _getExecutionDuration (StepResult stepResult) {
98- return ' (${stepResult .elapsedMilliseconds }ms)' ;
99- }
89+ String _getReasonMessage (StepResult stepResult) =>
90+ (stepResult.resultReason != null && stepResult.resultReason! .isNotEmpty)
91+ ? '\n ${stepResult .resultReason }'
92+ : '' ;
93+
94+ String _getErrorMessage (StepResult stepResult) =>
95+ stepResult is ErroredStepResult
96+ ? '\n ${stepResult .exception }\n ${stepResult .stackTrace }'
97+ : '' ;
98+
99+ String _getContext (RunnableDebugInformation ? context) => neutralColor (
100+ "\t # ${_getFeatureFilePath (context )}:${context ?.lineNumber }" );
101+
102+ String _getFeatureFilePath (RunnableDebugInformation ? context) =>
103+ context? .filePath.replaceAll (RegExp (r'\.\\' ), '' ) ?? '' ;
104+
105+ String _getExecutionDuration (StepResult stepResult) =>
106+ ' (${stepResult .elapsedMilliseconds }ms)' ;
100107
101108 String _getStatePrefixIcon (StepExecutionResult result) {
102109 switch (result) {
103- case StepExecutionResult .pass :
110+ case StepExecutionResult .passed :
104111 return '√' ;
105112 case StepExecutionResult .error:
106113 case StepExecutionResult .fail:
0 commit comments