From 591038ba4f718007cacdf7a4f58b3c375fa2ee97 Mon Sep 17 00:00:00 2001 From: Clombrong Date: Fri, 30 May 2025 10:55:32 +0200 Subject: test(js): move portal tests to global tests --- portal/test/js/dune | 14 -------------- portal/test/js/package-lock.json | 21 --------------------- portal/test/js/package.json | 5 ----- portal/test/js/polyfill.js | 1 - portal/test/js/websockets_hello.ml | 28 ---------------------------- test/js/dune | 14 ++++++++++++++ test/js/package-lock.json | 21 +++++++++++++++++++++ test/js/package.json | 5 +++++ test/js/polyfill.js | 1 + test/js/websockets_hello.ml | 28 ++++++++++++++++++++++++++++ 10 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 portal/test/js/dune delete mode 100644 portal/test/js/package-lock.json delete mode 100644 portal/test/js/package.json delete mode 100644 portal/test/js/polyfill.js delete mode 100644 portal/test/js/websockets_hello.ml create mode 100644 test/js/dune create mode 100644 test/js/package-lock.json create mode 100644 test/js/package.json create mode 100644 test/js/polyfill.js create mode 100644 test/js/websockets_hello.ml diff --git a/portal/test/js/dune b/portal/test/js/dune deleted file mode 100644 index b34c980..0000000 --- a/portal/test/js/dune +++ /dev/null @@ -1,14 +0,0 @@ -(test - (name websockets_hello) - (libraries portal_ws lwt js_of_ocaml) - (modes js) - (preprocess (pps js_of_ocaml-ppx)) - (deps node_modules) - (js_of_ocaml - (javascript_files polyfill.js))) - -(rule - (alias npm) - (target node_modules) - (deps package.json package-lock.json) - (action (system "npm ci"))) diff --git a/portal/test/js/package-lock.json b/portal/test/js/package-lock.json deleted file mode 100644 index 8b5d148..0000000 --- a/portal/test/js/package-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "js", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "xmlhttprequest": "^1.8.0" - } - }, - "node_modules/xmlhttprequest": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", - "integrity": "sha512-58Im/U0mlVBLM38NdZjHyhuMtCqa61469k2YP/AaPbvCoV9aQGUpbJBj1QRm2ytRiVQBD/fsw7L2bJGDVQswBA==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - } - } -} diff --git a/portal/test/js/package.json b/portal/test/js/package.json deleted file mode 100644 index 3b36bf4..0000000 --- a/portal/test/js/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "xmlhttprequest": "^1.8.0" - } -} diff --git a/portal/test/js/polyfill.js b/portal/test/js/polyfill.js deleted file mode 100644 index e394ec8..0000000 --- a/portal/test/js/polyfill.js +++ /dev/null @@ -1 +0,0 @@ -global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; diff --git a/portal/test/js/websockets_hello.ml b/portal/test/js/websockets_hello.ml deleted file mode 100644 index 5705dc9..0000000 --- a/portal/test/js/websockets_hello.ml +++ /dev/null @@ -1,28 +0,0 @@ -open Lwt.Syntax -open Js_of_ocaml - -(* https://stackoverflow.com/questions/34929382/what-are-the-differences-between-lwt-async-and-lwt-main-run-on-ocaml-node-js *) -let rec run t = - let next_tick (_callback : unit -> unit) = - Js.Unsafe.(fun_call - (js_expr "process.nextTick") - [| inject (Js.wrap_callback _callback) |]) - in Lwt.wakeup_paused (); - match Lwt.poll t with - | Some x -> x - | None -> - if Lwt.paused_count () > 0 - then next_tick (fun () -> run t) - else () - -let () = - run @@ - let domain = "egregore.fun" in - let* stream, push = - Portal.connect domain in - push (Some (Portal.stanza_open domain)); - push (Some Portal.stanza_close); - Lwt_stream.iter - (fun stanza -> - print_endline (">>> " ^ stanza)) - stream diff --git a/test/js/dune b/test/js/dune new file mode 100644 index 0000000..b34c980 --- /dev/null +++ b/test/js/dune @@ -0,0 +1,14 @@ +(test + (name websockets_hello) + (libraries portal_ws lwt js_of_ocaml) + (modes js) + (preprocess (pps js_of_ocaml-ppx)) + (deps node_modules) + (js_of_ocaml + (javascript_files polyfill.js))) + +(rule + (alias npm) + (target node_modules) + (deps package.json package-lock.json) + (action (system "npm ci"))) diff --git a/test/js/package-lock.json b/test/js/package-lock.json new file mode 100644 index 0000000..8b5d148 --- /dev/null +++ b/test/js/package-lock.json @@ -0,0 +1,21 @@ +{ + "name": "js", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "xmlhttprequest": "^1.8.0" + } + }, + "node_modules/xmlhttprequest": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", + "integrity": "sha512-58Im/U0mlVBLM38NdZjHyhuMtCqa61469k2YP/AaPbvCoV9aQGUpbJBj1QRm2ytRiVQBD/fsw7L2bJGDVQswBA==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + } + } +} diff --git a/test/js/package.json b/test/js/package.json new file mode 100644 index 0000000..3b36bf4 --- /dev/null +++ b/test/js/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "xmlhttprequest": "^1.8.0" + } +} diff --git a/test/js/polyfill.js b/test/js/polyfill.js new file mode 100644 index 0000000..e394ec8 --- /dev/null +++ b/test/js/polyfill.js @@ -0,0 +1 @@ +global.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml new file mode 100644 index 0000000..5705dc9 --- /dev/null +++ b/test/js/websockets_hello.ml @@ -0,0 +1,28 @@ +open Lwt.Syntax +open Js_of_ocaml + +(* https://stackoverflow.com/questions/34929382/what-are-the-differences-between-lwt-async-and-lwt-main-run-on-ocaml-node-js *) +let rec run t = + let next_tick (_callback : unit -> unit) = + Js.Unsafe.(fun_call + (js_expr "process.nextTick") + [| inject (Js.wrap_callback _callback) |]) + in Lwt.wakeup_paused (); + match Lwt.poll t with + | Some x -> x + | None -> + if Lwt.paused_count () > 0 + then next_tick (fun () -> run t) + else () + +let () = + run @@ + let domain = "egregore.fun" in + let* stream, push = + Portal.connect domain in + push (Some (Portal.stanza_open domain)); + push (Some Portal.stanza_close); + Lwt_stream.iter + (fun stanza -> + print_endline (">>> " ^ stanza)) + stream -- cgit v1.2.3