-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace react dom's testing library with ReactTestingLibrary #859
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
35d588c
Install melange-testing-library
davesnx 1cd6a6b
Install melange-testing-library npm deps
davesnx 05aa7e1
Vendor melange-testing-library
davesnx 4434bfd
Fix Form__test with RTL
davesnx ab43c4b
Start migrating Hooks__test
davesnx 8234b69
Remove dependency
davesnx 49b35e9
Remove unused code from Form__test
davesnx 3ca3ba1
Add a jest-devtoolsgs
davesnx 41ba9c2
Add a jest-devtools
davesnx c7998a9
Migrate Hooks and Form into RTL
davesnx 5e05f2e
Add demo to manually test easily
davesnx f8a08c3
Use Uncurried for tests
davesnx 8d156d7
Migrate all React__test
davesnx 33ad56a
Force install since we are dealing with R19
davesnx 30d82df
Snapshot with lower {}
davesnx 80e85ae
Remove jest from demo/dune
davesnx b39168f
Add comment on install --force
davesnx 7aaef3e
Merge branch '19' of github.com:/reasonml/reason-react into replace-t…
davesnx 5171ac5
Bind React.act and React.actAsync
davesnx ad36fbb
Bind React.act and React.actAsync
davesnx 52addbc
Merge branch 'replace-testing-libraries' of github.com:/reasonml/reas…
davesnx 2f5ae8d
Use React.act as async version only
davesnx 44faccc
Test react.act and react.actasync
davesnx d168359
Fix hola test :(
davesnx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(melange.emit | ||
(target demo) | ||
(alias melange-app) | ||
(module_systems | ||
(es6 mjs)) | ||
(libraries reason-react melange.belt melange.dom) | ||
(runtime_deps index.html) | ||
(preprocess | ||
(pps melange.ppx reason-react-ppx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Demo reason-react</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css-1.8.1.min.css" /> | ||
<style> | ||
body { | ||
padding: 2rem; | ||
} | ||
|
||
#root { | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 900px; | ||
} | ||
</style> | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"melange/": "./demo/node_modules/melange/", | ||
"melange.belt/": "./demo/node_modules/melange.belt/", | ||
"melange.js/": "./demo/node_modules/melange.js/", | ||
"reason-react/": "./demo/node_modules/reason-react/", | ||
"react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime", | ||
"react": "https://esm.sh/[email protected]", | ||
"react-dom": "https://esm.sh/[email protected]", | ||
"react-dom/client": "https://esm.sh/[email protected]/client" | ||
} | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
</body> | ||
<script type="module" src="./demo/demo/main.mjs"></script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
module Stateful = { | ||
[@react.component] | ||
let make = (~title, ~initialValue=0, ~children=React.null) => { | ||
let (value, setValue) = React.useState(() => initialValue); | ||
let onClick = _ => setValue(value => value + 1); | ||
|
||
<section> | ||
<h3> {React.string(title)} </h3> | ||
<button key="asdf" onClick> value->React.int </button> | ||
children | ||
</section>; | ||
}; | ||
}; | ||
|
||
module Reducer = { | ||
type action = | ||
| Increment | ||
| Decrement; | ||
|
||
[@react.component] | ||
let make = (~initialValue=0) => { | ||
let (state, send) = | ||
React.useReducer( | ||
(state, action) => | ||
switch (action) { | ||
| Increment => state + 1 | ||
| Decrement => state - 1 | ||
}, | ||
initialValue, | ||
); | ||
|
||
Js.log2("Reducer state", state); | ||
|
||
<section> | ||
<h3> {React.string("React.useReducer")} </h3> | ||
<main> state->React.int </main> | ||
<button onClick={_ => send(Increment)}> | ||
"Increment"->React.string | ||
</button> | ||
<button onClick={_ => send(Decrement)}> | ||
"Decrement"->React.string | ||
</button> | ||
</section>; | ||
}; | ||
}; | ||
|
||
module ReducerWithMapState = { | ||
type action = | ||
| Increment | ||
| Decrement; | ||
|
||
[@react.component] | ||
let make = (~initialValue=0) => { | ||
let (state, send) = | ||
React.useReducerWithMapState( | ||
(state, action) => | ||
switch (action) { | ||
| Increment => state + 1 | ||
| Decrement => state - 1 | ||
}, | ||
initialValue, | ||
initialValue => initialValue + 75, | ||
); | ||
|
||
Js.log2("ReducerWithMapState state", state); | ||
|
||
<section> | ||
<h3> {React.string("React.useReducerWithMapState")} </h3> | ||
<main> state->React.int </main> | ||
<button onClick={_ => send(Increment)}> | ||
"Increment"->React.string | ||
</button> | ||
<button onClick={_ => send(Decrement)}> | ||
"Decrement"->React.string | ||
</button> | ||
</section>; | ||
}; | ||
}; | ||
|
||
module WithEffect = { | ||
[@react.component] | ||
let make = (~value) => { | ||
React.useEffect1( | ||
() => { | ||
Js.log("useEffect"); | ||
None; | ||
}, | ||
[|value|], | ||
); | ||
|
||
React.string("React.useEffect"); | ||
}; | ||
}; | ||
|
||
module RerenderOnEachClick = { | ||
[@react.component] | ||
let make = (~value=0, ~callback as _) => { | ||
let (value, setValue) = React.useState(() => value); | ||
let onClick = _ => | ||
if (value < 3) { | ||
Js.log2("Clicked with:", value); | ||
setValue(value => value + 1); | ||
} else { | ||
Js.log("Max value reached, not firing a rerender"); | ||
setValue(value => value); | ||
}; | ||
|
||
<section> | ||
<h3> {React.string("RerenderOnEachClick")} </h3> | ||
<button onClick> <WithEffect value /> </button> | ||
</section>; | ||
}; | ||
}; | ||
|
||
module WithLayoutEffect = { | ||
[@react.component] | ||
let make = (~value=0, ~callback) => { | ||
React.useLayoutEffect1( | ||
() => { | ||
callback(value); | ||
Js.log("useLayoutEffect"); | ||
None; | ||
}, | ||
[|value|], | ||
); | ||
|
||
<section> <h3> {React.string("React.useLayoutEffect")} </h3> </section>; | ||
}; | ||
}; | ||
|
||
module WithRefAndEffect = { | ||
[@react.component] | ||
let make = (~callback) => { | ||
let myRef = React.useRef(1); | ||
React.useEffect0(() => { | ||
myRef.current = myRef.current + 1; | ||
callback(myRef); | ||
None; | ||
}); | ||
|
||
<section> | ||
<h3> {React.string("React.useRef and useEffect")} </h3> | ||
<main> {React.int(myRef.current)} </main> | ||
</section>; | ||
}; | ||
}; | ||
|
||
[@mel.module "react"] | ||
external useReducer: | ||
([@mel.uncurry] (('state, 'action) => 'state), 'state) => | ||
('state, 'action => unit) = | ||
"useReducer"; | ||
|
||
module UseReducerNoProblemo = { | ||
[@react.component] | ||
let make = () => { | ||
let reducer = (v, _) => v + 1; | ||
let (state, send) = useReducer(reducer, 0); | ||
Js.log("asdfasd"); | ||
<button onClick={_ => send(0)}> {React.int(state)} </button>; | ||
}; | ||
}; | ||
|
||
module App = { | ||
[@react.component] | ||
let make = (~initialValue) => { | ||
let value = 99; | ||
let callback = _number => (); | ||
|
||
<main> | ||
<Stateful title="Stateful" initialValue /> | ||
<Reducer key="reducer" initialValue /> | ||
<ReducerWithMapState key="reducer-with-map-state" initialValue /> | ||
<RerenderOnEachClick key="rerender-on-each-click" value=0 callback /> | ||
<WithLayoutEffect key="layout-effect" value callback /> | ||
<WithRefAndEffect key="ref-and-effect" callback /> | ||
<UseReducerNoProblemo /> | ||
</main>; | ||
}; | ||
}; | ||
|
||
switch (ReactDOM.querySelector("#root")) { | ||
| Some(el) => | ||
let root = ReactDOM.Client.createRoot(el); | ||
ReactDOM.Client.render(root, <App initialValue=0 />); | ||
| None => Js.log("No root element found") | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(dirs src test ppx) | ||
(dirs src test ppx demo) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was
force
needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because testinglib and other deps depend on react 18, so npm complains. It is a decent workaround to ensure the installation succeeds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will write a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would we still needed
--force
if you commit the lockfile from manual install and runnpm ci
here?