@@ -25,6 +25,7 @@ import * as http from "http";
25
25
import { Content , DefaultContent , ContentSerdes , createLoggers , ProtocolServer } from "@node-wot/core" ;
26
26
27
27
import { Readable } from "stream" ;
28
+ import { text } from "node:stream/consumers" ;
28
29
29
30
import HttpClient from "../src/http-client" ;
30
31
import { HttpForm } from "../src/http" ;
@@ -37,6 +38,7 @@ import FakeTimers from "@sinonjs/fake-timers";
37
38
38
39
// Add spies
39
40
import spies from "chai-spies" ;
41
+ import { fail } from "assert" ;
40
42
41
43
const { debug } = createLoggers ( "binding-http" , "http-client-test" ) ;
42
44
@@ -425,6 +427,8 @@ class HttpClientTest1 {
425
427
@suite ( "HTTP client subscriptions" )
426
428
class HttpClientTest2 {
427
429
@test "should register to sse server and get server sent event" ( done : Mocha . Done ) {
430
+ let dataCheckError : string | undefined ;
431
+
428
432
// create sse server
429
433
const clock = FakeTimers . install ( ) ;
430
434
const app = express ( ) ;
@@ -445,6 +449,9 @@ class HttpClientTest2 {
445
449
clearInterval ( pusher ) ;
446
450
sseStream . unpipe ( res ) ;
447
451
done ( ) ;
452
+ if ( dataCheckError !== undefined ) {
453
+ fail ( dataCheckError ) ;
454
+ }
448
455
} ) ;
449
456
} ) ;
450
457
@@ -463,7 +470,10 @@ class HttpClientTest2 {
463
470
} ;
464
471
465
472
client
466
- . subscribeResource ( form , ( data ) => {
473
+ . subscribeResource ( form , async ( data ) => {
474
+ if ( ( await text ( data . body ) ) !== "Test event" ) {
475
+ dataCheckError = "Data should report 'Test event'" ;
476
+ }
467
477
client . unlinkResource ( form ) ;
468
478
server . close ( ) ;
469
479
clock . uninstall ( ) ;
0 commit comments