18
18
import java .time .Clock ;
19
19
import java .util .Collections ;
20
20
import java .util .UUID ;
21
+ import java .util .regex .Matcher ;
22
+ import java .util .regex .Pattern ;
21
23
22
- import static io .cucumber .core .plugin .Bytes .bytes ;
23
- import static org .hamcrest .CoreMatchers .containsString ;
24
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
24
25
import static org .hamcrest .MatcherAssert .assertThat ;
26
+ import static org .skyscreamer .jsonassert .JSONAssert .assertEquals ;
27
+ import static org .skyscreamer .jsonassert .JSONCompareMode .STRICT ;
25
28
26
29
class HtmlFormatterTest {
27
30
@@ -38,11 +41,11 @@ void writes_index_html() throws Throwable {
38
41
TestRunFinished testRunFinished = new TestRunFinished (null , true , new Timestamp (15L , 0L ), null );
39
42
bus .send (Envelope .of (testRunFinished ));
40
43
41
- assertThat ( bytes , bytes ( containsString ( " " +
42
- "window.CUCUMBER_MESSAGES = [ " +
43
- "{\" testRunStarted \" :{\" timestamp\" :{\" seconds \" :10 ,\" nanos \" :0 }}}, " +
44
- "{ \" testRunFinished \" :{ \" success \" :true, \" timestamp \" :{ \" seconds \" :15, \" nanos \" :0}}}" +
45
- "]; \n " )) );
44
+ assertEquals ( "[ " +
45
+ "{ \" testRunStarted \" :{ \" timestamp \" :{ \" nanos \" :0, \" seconds \" :10}}}, " +
46
+ "{\" testRunFinished \" :{\" success \" :true, \" timestamp\" :{\" nanos \" :0 ,\" seconds \" :15 }}}" +
47
+ "]" ,
48
+ extractCucumberMessages ( bytes ), STRICT );
46
49
}
47
50
48
51
@ Test
@@ -86,11 +89,17 @@ void ignores_step_definitions() throws Throwable {
86
89
null );
87
90
bus .send (Envelope .of (testRunFinished ));
88
91
89
- assertThat ( bytes , bytes ( containsString ( " " +
90
- "window.CUCUMBER_MESSAGES = [ " +
91
- "{\" testRunStarted \" :{\" timestamp\" :{\" seconds \" :10 ,\" nanos \" :0 }}}, " +
92
- "{ \" testRunFinished \" :{ \" success \" :true, \" timestamp \" :{ \" seconds \" :15, \" nanos \" :0}}}" +
93
- "]; \n " )) );
92
+ assertEquals ( "[ " +
93
+ "{ \" testRunStarted \" :{ \" timestamp \" :{ \" nanos \" :0, \" seconds \" :10}}}, " +
94
+ "{\" testRunFinished \" :{\" success \" :true, \" timestamp\" :{\" nanos \" :0 ,\" seconds \" :15 }}}" +
95
+ "]" ,
96
+ extractCucumberMessages ( bytes ), STRICT );
94
97
}
95
98
99
+ private static String extractCucumberMessages (ByteArrayOutputStream bytes ) {
100
+ Pattern pattern = Pattern .compile ("^.*window\\ .CUCUMBER_MESSAGES = (\\ [.+]);.*$" , Pattern .DOTALL );
101
+ Matcher matcher = pattern .matcher (new String (bytes .toByteArray (), UTF_8 ));
102
+ assertThat ("bytes must match " + pattern , matcher .find ());
103
+ return matcher .group (1 );
104
+ }
96
105
}
0 commit comments