Skip to content

RFC: Revamp TestUtils & tests #14

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [14.x]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add 16 since it's the current LTS release.


steps:
- uses: actions/checkout@v2
4 changes: 2 additions & 2 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@
"name": "@rescript/react",
"reason": { "react-jsx": 3 },
"sources": [
{"dir": "src", "subdirs": true},
{ "dir": "src", "subdirs": true },
{ "dir": "test", "type": "dev" }
],
"package-specs": [{ "module": "commonjs", "in-source": true }],
"suffix": ".bs.js",
"bs-dev-dependencies": ["reason-test-framework"],
"bs-dev-dependencies": ["rescript-test"],
"bsc-flags": []
}
4,617 changes: 341 additions & 4,276 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 8 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world",
"test": "echo 'tests disabled for now'"
"test": "retest --with-dom test/*.bs.js"
},
"keywords": [
"rescript",
@@ -28,29 +28,14 @@
},
"homepage": "https://rescript-lang.org/docs/react/latest/introduction",
"devDependencies": {
"bs-platform": "8.3.0",
"jest": "^26.0.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"reason-test-framework": "^0.3.2"
"bs-platform": "^8.4.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"rescript-test": "^2.0.5"
},
"peerDependencies": {
"bs-platform": "^8.3.0",
"react": "^16.8.1",
"react-dom": "^16.8.1"
},
"jest": {
"moduleDirectories": [
"node_modules"
],
"roots": [
"test"
],
"testMatch": [
"**/*__test.bs.js"
],
"transformIgnorePatterns": [
"node_modules/(?!(bs-platform|reason-react|reason-react-compat|reason-react-update|bs-webapi|bs-css|bs-css-emotion|reason-test-framework)/)"
]
"bs-platform": ">=8.3.0",
"react": ">=16.8.1",
"react-dom": ">=16.8.1"
}
}
463 changes: 338 additions & 125 deletions src/ReactTestUtils.res

Large diffs are not rendered by default.

386 changes: 338 additions & 48 deletions src/ReactTestUtils.resi

Large diffs are not rendered by default.

565 changes: 276 additions & 289 deletions test/React__test.res

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions test/RescriptReactRouter__test.res
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
open TestFramework
open Test
open RescriptReactRouter

describe("it allows to create url from string", ({test}) => {
test("it supports basic paths", ({expect}) => {
let expected = {path: list{"foo", "bar"}, hash: "", search: ""}
let generated = dangerouslyGetInitialUrl(~serverUrlString="/foo/bar", ())
let urlEquals = (~message=?, expected: RescriptReactRouter.url, actual: RescriptReactRouter.url) =>
assertion(
~message?,
~operator="boolEquals",
(a, b) =>
Belt.List.eq(a.path, b.path, (a, b) => a === b) && a.search === b.search && a.hash === b.hash,
expected,
actual,
)

expect.bool(generated == expected).toBeTrue()
})
test("RescriptReactRouter allows to create url from string: basic paths", () => {
let expected = {path: list{"foo", "bar"}, hash: "", search: ""}
let generated = dangerouslyGetInitialUrl(~serverUrlString="/foo/bar", ())

test("it creates with search", ({expect}) => {
let expected = {path: list{"foo", "bar"}, hash: "", search: "q=term"}
let generated = dangerouslyGetInitialUrl(~serverUrlString="/foo/bar?q=term", ())
urlEquals(generated, expected)
})

test("RescriptReactRouter creates urls with search", () => {
let expected = {path: list{"foo", "bar"}, hash: "", search: "q=term"}
let generated = dangerouslyGetInitialUrl(~serverUrlString="/foo/bar?q=term", ())

expect.bool(generated == expected).toBeTrue()
})
urlEquals(generated, expected)
})