@@ -25,6 +25,7 @@ import * as http from "http";
2525import { Content , DefaultContent , ContentSerdes , createLoggers , ProtocolServer } from "@node-wot/core" ;
2626
2727import { Readable } from "stream" ;
28+ import { text } from "node:stream/consumers" ;
2829
2930import HttpClient from "../src/http-client" ;
3031import { HttpForm } from "../src/http" ;
@@ -37,6 +38,7 @@ import FakeTimers from "@sinonjs/fake-timers";
3738
3839// Add spies
3940import spies from "chai-spies" ;
41+ import { fail } from "assert" ;
4042
4143const { debug } = createLoggers ( "binding-http" , "http-client-test" ) ;
4244
@@ -425,6 +427,8 @@ class HttpClientTest1 {
425427@suite ( "HTTP client subscriptions" )
426428class HttpClientTest2 {
427429 @test "should register to sse server and get server sent event" ( done : Mocha . Done ) {
430+ let dataCheckError : string | undefined ;
431+
428432 // create sse server
429433 const clock = FakeTimers . install ( ) ;
430434 const app = express ( ) ;
@@ -445,6 +449,9 @@ class HttpClientTest2 {
445449 clearInterval ( pusher ) ;
446450 sseStream . unpipe ( res ) ;
447451 done ( ) ;
452+ if ( dataCheckError !== undefined ) {
453+ fail ( dataCheckError ) ;
454+ }
448455 } ) ;
449456 } ) ;
450457
@@ -463,7 +470,10 @@ class HttpClientTest2 {
463470 } ;
464471
465472 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+ }
467477 client . unlinkResource ( form ) ;
468478 server . close ( ) ;
469479 clock . uninstall ( ) ;
0 commit comments