HS: socket on-message + as JSON (+3)
Steps 4-5 complete: hs-try-json-parse, ws.onmessage wiring (text/JSON dispatch), onmessage test cases. 8/16 socket tests passing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11530,11 +11530,29 @@
|
||||
(let ((chat (host-get my-app "chat")))
|
||||
(assert (not (nil? (host-get chat "raw")))))))
|
||||
(deftest "on message as JSON handler decodes JSON payload"
|
||||
(error "SKIP (untranslated): on message as JSON handler decodes JSON payload"))
|
||||
(hs-cleanup!)
|
||||
(eval-hs "socket JsonSocket ws://localhost/ws on message as JSON set window.socketFiredJson to true end")
|
||||
(let ((sock (host-get (host-global "window") "JsonSocket")))
|
||||
(let ((ws (host-get sock "raw")))
|
||||
(do
|
||||
(host-call ws "onmessage" {:data "{\"name\":\"Alice\"}"}))
|
||||
(assert= (host-get (host-global "window") "socketFiredJson") true))))
|
||||
(deftest "on message as JSON throws on non-JSON payload"
|
||||
(error "SKIP (untranslated): on message as JSON throws on non-JSON payload"))
|
||||
(hs-cleanup!)
|
||||
(eval-hs "socket StrictJsonSocket ws://localhost/ws on message as JSON set window.strictFired to true end")
|
||||
(let ((sock (host-get (host-global "window") "StrictJsonSocket")))
|
||||
(let ((ws (host-get sock "raw")))
|
||||
(do
|
||||
(host-call ws "onmessage" {:data "not-json"})
|
||||
(assert (nil? (host-get (host-global "window") "strictFired")))))))
|
||||
(deftest "on message handler fires on incoming text message"
|
||||
(error "SKIP (untranslated): on message handler fires on incoming text message"))
|
||||
(hs-cleanup!)
|
||||
(eval-hs "socket TextSocket ws://localhost/ws on message set window.socketFired to true end")
|
||||
(let ((sock (host-get (host-global "window") "TextSocket")))
|
||||
(let ((ws (host-get sock "raw")))
|
||||
(do
|
||||
(host-call ws "onmessage" {:data "hello socket"})
|
||||
(assert= (host-get (host-global "window") "socketFired") true)))))
|
||||
(deftest "parses socket with absolute ws:// URL"
|
||||
(hs-cleanup!)
|
||||
(host-set! (host-global "window") "__hs_ws_created" (list))
|
||||
|
||||
Reference in New Issue
Block a user