@@ -427,6 +427,35 @@ func TestBinaryType_ArrayBuffer(t *testing.T) {
427427 require .Len (t , logs , 0 )
428428}
429429
430+ func TestBinaryType_ArrayBuffer_issue_5226 (t * testing.T ) {
431+ t .Parallel ()
432+ ts := newTestState (t )
433+ logger , hook := testutils .NewLoggerWithHook (t , logrus .WarnLevel )
434+ ts .runtime .VU .StateField .Logger = logger
435+ _ , err := ts .runtime .RunOnEventLoop (ts .tb .Replacer .Replace (`
436+ var ws = new WebSocket("WSBIN_URL/ws-echo")
437+ ws.binaryType = "arraybuffer"
438+ ws.addEventListener("open", () => {
439+ const sent = new Uint8Array(1024)
440+ ws.send(sent.subarray(0, 1))
441+ ws.onmessage = (e) => {
442+ if (!(e.data instanceof ArrayBuffer)) {
443+ throw new Error("Wrong event.data type; expected: ArrayBuffer, got: "+ typeof e.data);
444+ }
445+
446+ if (e.data.byteLength != 1) {
447+ throw new Error("The data received isn't equal to the data sent " + e.data.byteLength);
448+ }
449+
450+ ws.close();
451+ }
452+ })
453+ ` ))
454+ require .NoError (t , err )
455+ logs := hook .Drain ()
456+ require .Len (t , logs , 0 )
457+ }
458+
430459func TestExceptionDontPanic (t * testing.T ) {
431460 t .Parallel ()
432461 cases := map [string ]struct {
@@ -1050,7 +1079,7 @@ func TestCookiesDefaultJar(t *testing.T) {
10501079
10511080 ts .runtime .VU .StateField .CookieJar , _ = cookiejar .New (nil )
10521081 _ , err = ts .runtime .RunOnEventLoop (sr (`
1053- http.cookieJar().set("HTTPBIN_URL/ws-echo-someheader", "someheader", "defaultjar")
1082+ http.cookieJar().set("HTTPBIN_URL/ws-echo-someheader", "someheader", "defaultjar")
10541083
10551084 var ws = new WebSocket("WSBIN_URL/ws-echo-someheader", null)
10561085 ws.onopen = () => {
@@ -1372,7 +1401,7 @@ func TestSessionPingAdd(t *testing.T) {
13721401 ts := newTestState (t )
13731402
13741403 _ , err := ts .runtime .RunOnEventLoop (sr (`
1375- var ws = new WebSocket("WSBIN_URL/ws-echo")
1404+ var ws = new WebSocket("WSBIN_URL/ws-echo")
13761405 ws.addEventListener("open", () => {
13771406 ws.ping()
13781407 })
0 commit comments