From cecbf9b8d347dc3e6fd46e16ccf1d8c4a3d19c04 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 22 Nov 2026 11:24:52 -0800 Subject: [PATCH 1/2] test: reproduce consumers without emitted Stdlib --- test/ReactDOMTestUtils__test.re | 61 +++++++++++++++++++ test/ReactRouter__test.re | 21 +++++++ .../without-emitted-stdlib.t/consumer.re | 11 ++++ .../without-emitted-stdlib.t/run.t | 22 +++++++ 4 files changed, 115 insertions(+) create mode 100644 test/ReactDOMTestUtils__test.re create mode 100644 test/blackbox-tests/without-emitted-stdlib.t/consumer.re create mode 100644 test/blackbox-tests/without-emitted-stdlib.t/run.t diff --git a/test/ReactDOMTestUtils__test.re b/test/ReactDOMTestUtils__test.re new file mode 100644 index 000000000..2916eed25 --- /dev/null +++ b/test/ReactDOMTestUtils__test.re @@ -0,0 +1,61 @@ +[@alert "-deprecated"]; + +open Jest; +open Jest.Expect; + +external document: Dom.document = "document"; +[@mel.send] +external createElement: (Dom.document, string) => Dom.element = + "createElement"; +[@mel.set] external setInnerHTML: (Dom.element, string) => unit = "innerHTML"; +[@mel.send] +external querySelector: (Dom.element, string) => Dom.element = "querySelector"; + +describe("DOM text queries", () => { + let container = document->createElement("div"); + container->setInnerHTML( + "Hello caféHello café again", + ); + let first = container->querySelector("#first"); + + test("it finds exact text and the first partial match", () => { + let exact = + ReactDOMTestUtils.DOM.findBySelectorAndTextContent( + container, + "span", + "Hello café", + ); + let partial = + ReactDOMTestUtils.DOM.findBySelectorAndPartialTextContent( + container, + "span", + "café", + ); + expect(Option.get(exact))->toBe(first); + expect(Option.get(partial))->toBe(first); + }); + + test("it returns None when no element or text matches", () => { + List.iter( + ((selector, content)) => { + expect( + ReactDOMTestUtils.DOM.findBySelectorAndTextContent( + container, + selector, + content, + ), + ) + ->toEqual(None); + expect( + ReactDOMTestUtils.DOM.findBySelectorAndPartialTextContent( + container, + selector, + content, + ), + ) + ->toEqual(None); + }, + [("span", "absent"), (".missing", "Hello café")], + ) + }); +}); diff --git a/test/ReactRouter__test.re b/test/ReactRouter__test.re index f69471371..7f34c6356 100644 --- a/test/ReactRouter__test.re +++ b/test/ReactRouter__test.re @@ -25,4 +25,25 @@ describe("it allows to create url from string", () => { expect(generated == expected)->toBe(true); }); + + test("it preserves path order and skips empty segments", () => { + let generated = + dangerouslyGetInitialUrl( + ~serverUrlString="//first///second/third//?q=term", + (), + ); + + expect(generated.path)->toEqual(["first", "second", "third"]); + expect(generated.search)->toBe("q=term"); + }); + + test("it supports empty and root paths", () => { + List.iter( + serverUrlString => { + let generated = dangerouslyGetInitialUrl(~serverUrlString, ()); + expect(generated.path)->toEqual([]); + }, + ["", "/", "///"], + ) + }); }); diff --git a/test/blackbox-tests/without-emitted-stdlib.t/consumer.re b/test/blackbox-tests/without-emitted-stdlib.t/consumer.re new file mode 100644 index 000000000..37c42f0c1 --- /dev/null +++ b/test/blackbox-tests/without-emitted-stdlib.t/consumer.re @@ -0,0 +1,11 @@ +module App = { + [@react.component] + let make = () =>
"Hello"->React.string
; +}; + +let url = + ReasonReactRouter.dangerouslyGetInitialUrl(~serverUrlString="/foo/bar", ()); + +let findText = ReactDOMTestUtils.DOM.findBySelectorAndTextContent; +let findPartialText = ReactDOMTestUtils.DOM.findBySelectorAndPartialTextContent; +let renderToPipeableStream = ReactDOMServerNode.renderToPipeableStream; diff --git a/test/blackbox-tests/without-emitted-stdlib.t/run.t b/test/blackbox-tests/without-emitted-stdlib.t/run.t new file mode 100644 index 000000000..52de9d8c6 --- /dev/null +++ b/test/blackbox-tests/without-emitted-stdlib.t/run.t @@ -0,0 +1,22 @@ +Use the router, DOM test helpers, and Node bindings without emitting the standard +library. A consumer should only need ReasonReact and the Melange JavaScript runtime. + + $ cat > dune-project < (lang dune 3.8) + > (using melange 0.1) + > EOF + + $ cat > dune < (melange.emit + > (target output) + > (alias mel) + > (emit_stdlib false) + > (compile_flags :standard -nopervasives -nostdlib -alert -deprecated) + > (libraries reason-react reason-react.node) + > (preprocess (pps melange.ppx reason-react-ppx))) + > EOF + + $ dune build --display quiet @mel + File "_none_", line 1: + Error: Stdlib__Array not found, it means either the module does not exist or it is a namespace + [1] From 729293663536361959e381617f9e1081bfd3a120 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 22 Nov 2026 11:27:31 -0800 Subject: [PATCH 2/2] test: check that consumers do not emit Stdlib transitively --- test/blackbox-tests/without-emitted-stdlib.t/run.t | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/blackbox-tests/without-emitted-stdlib.t/run.t b/test/blackbox-tests/without-emitted-stdlib.t/run.t index 52de9d8c6..e9ac692c4 100644 --- a/test/blackbox-tests/without-emitted-stdlib.t/run.t +++ b/test/blackbox-tests/without-emitted-stdlib.t/run.t @@ -20,3 +20,7 @@ library. A consumer should only need ReasonReact and the Melange JavaScript runt File "_none_", line 1: Error: Stdlib__Array not found, it means either the module does not exist or it is a namespace [1] + +Stdlib must not be pulled in through a transitive library dependency either. + + $ test ! -d _build/default/output/node_modules/melange