@@ -60,37 +60,37 @@ public void uri(String uri) {
60
60
.append (JS_FORMATTER_VAR ).append (" = new CucumberHTML.DOMFormatter($('.cucumber-report'));" );
61
61
firstFeature = false ;
62
62
}
63
- writeToJsReport ("uri" , "'" + uri + "'" );
63
+ jsFunctionCall ("uri" , uri );
64
64
}
65
65
66
66
@ Override
67
67
public void feature (Feature feature ) {
68
- writeToJsReport ("feature" , feature );
68
+ jsFunctionCall ("feature" , feature );
69
69
}
70
70
71
71
@ Override
72
72
public void background (Background background ) {
73
- writeToJsReport ("background" , background );
73
+ jsFunctionCall ("background" , background );
74
74
}
75
75
76
76
@ Override
77
77
public void scenario (Scenario scenario ) {
78
- writeToJsReport ("scenario" , scenario );
78
+ jsFunctionCall ("scenario" , scenario );
79
79
}
80
80
81
81
@ Override
82
82
public void scenarioOutline (ScenarioOutline scenarioOutline ) {
83
- writeToJsReport ("scenarioOutline" , scenarioOutline );
83
+ jsFunctionCall ("scenarioOutline" , scenarioOutline );
84
84
}
85
85
86
86
@ Override
87
87
public void examples (Examples examples ) {
88
- writeToJsReport ("examples" , examples );
88
+ jsFunctionCall ("examples" , examples );
89
89
}
90
90
91
91
@ Override
92
92
public void step (Step step ) {
93
- writeToJsReport ("step" , step );
93
+ jsFunctionCall ("step" , step );
94
94
}
95
95
96
96
@ Override
@@ -114,34 +114,24 @@ public void close() {
114
114
jsOut ().close ();
115
115
}
116
116
117
- private void writeToJsReport (String functionName , String arg ) {
118
- String stringArg = gson .toJson (arg );
119
- jsOut ().append (JS_FORMATTER_VAR + "." ).append (functionName ).append ("(" ).append (stringArg ).append (");" ).println ();
120
- }
121
-
122
- private void writeToJsReport (String functionName , Mappable arg ) {
123
- String stringArg = gson .toJson (arg .toMap ());
124
- jsOut ().append (JS_FORMATTER_VAR + "." ).append (functionName ).append ("(" ).append (stringArg ).append (");" ).println ();
125
- }
126
-
127
117
@ Override
128
118
public void result (Result result ) {
129
- writeToJsReport ("result" , result );
119
+ jsFunctionCall ("result" , result );
130
120
}
131
121
132
122
@ Override
133
123
public void before (Match match , Result result ) {
134
- writeToJsReport ("before" , result );
124
+ jsFunctionCall ("before" , result );
135
125
}
136
126
137
127
@ Override
138
128
public void after (Match match , Result result ) {
139
- writeToJsReport ("after" , result );
129
+ jsFunctionCall ("after" , result );
140
130
}
141
131
142
132
@ Override
143
133
public void match (Match match ) {
144
- writeToJsReport ("match" , match );
134
+ jsFunctionCall ("match" , match );
145
135
}
146
136
147
137
@ Override
@@ -151,19 +141,34 @@ public void embedding(String mimeType, byte[] data) {
151
141
if (extension != null ) {
152
142
StringBuilder fileName = new StringBuilder ("embedded" ).append (embeddedIndex ++).append ("." ).append (extension );
153
143
writeBytesAndClose (data , reportFileOutputStream (fileName .toString ()));
154
- writeToJsReport ("embedding" , new StringBuilder ( "'" ). append ( mimeType ). append ( "','" ). append ( fileName ). append ( "'" ). toString () );
144
+ jsFunctionCall ("embedding" , mimeType , fileName );
155
145
}
156
146
}
157
147
158
148
@ Override
159
149
public void write (String text ) {
160
- writeToJsReport ("write" , text );
150
+ jsFunctionCall ("write" , text );
151
+ }
152
+
153
+ private void jsFunctionCall (String functionName , Object ... args ) {
154
+ NiceAppendable out = jsOut ().append (JS_FORMATTER_VAR + "." ).append (functionName ).append ("(" );
155
+ boolean comma = false ;
156
+ for (Object arg : args ) {
157
+ if (comma ) {
158
+ out .append (", " );
159
+ }
160
+ arg = arg instanceof Mappable ? ((Mappable ) arg ).toMap () : arg ;
161
+ String stringArg = gson .toJson (arg );
162
+ out .append (stringArg );
163
+ comma = true ;
164
+ }
165
+ out .append (");" ).println ();
161
166
}
162
167
163
168
private void copyReportFiles () {
164
169
for (String textAsset : TEXT_ASSETS ) {
165
170
InputStream textAssetStream = getClass ().getResourceAsStream (textAsset );
166
- if (textAssetStream == null ) {
171
+ if (textAssetStream == null ) {
167
172
throw new CucumberException ("Couldn't find " + textAsset + ". Is cucumber-html on your classpath? Make sure you have the right version." );
168
173
}
169
174
String baseName = new File (textAsset ).getName ();
0 commit comments