diff --git a/__tests__/App_test.res b/__tests__/App_test.res new file mode 100644 index 0000000..567e51a --- /dev/null +++ b/__tests__/App_test.res @@ -0,0 +1,33 @@ +open Test +open App +open Dom + +@get external textContent: Dom.element => string = "textContent" + +@module("@testing-library/react") +external act: (@uncurry unit => unit) => unit = "act" + +@val external window: {..} = "window" +@send external remove: Dom.element => unit = "remove" + +let createContainer = () => { + let containerElement: Dom.element = window["document"]["createElement"]("div") + let _ = window["document"]["body"]["appendChild"](containerElement) + containerElement +} + +let cleanupContainer = (container: Dom.element) => { + ReactDOM.unmountComponentAtNode(container) + remove(container) +} + +let testWithReact = testWith(~setup=createContainer, ~teardown=cleanupContainer) +let testAsyncWithReact = testAsyncWith(~setup=createContainer, ~teardown=cleanupContainer) + +testWithReact("Can render", container => { + act(() => ReactDOM.render(, container)) + + let countElement = ReactDOM.querySelector(".count") + + cleanupContainer(container) +}) diff --git a/bsconfig.json b/bsconfig.json index a51e5c2..b9729fd 100644 --- a/bsconfig.json +++ b/bsconfig.json @@ -4,6 +4,11 @@ { "dir": "src", "subdirs": true + }, + { + "dir": "__tests__", + "subdirs": true, + "type": "dev" } ], "package-specs": [ @@ -14,6 +19,12 @@ ], "suffix": ".bs.js", "bs-dependencies": ["@rescript/core", "@rescript/react"], + "bs-dev-dependencies": [ + "rescript-test", + "@glennsl/rescript-jest", + "rescript-nodejs", + "rescript-js" + ], "jsx": { "version": 4, "mode": "automatic" diff --git a/bun.lockb b/bun.lockb index aa1a8ae..15d2899 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs diff --git a/package.json b/package.json index fda8650..0b537fc 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "rspack-rescript-react", "private": true, "version": "1.0.0", + "type": "module", "scripts": { "dev": "concurrently \"bun run res:dev\" \"rspack serve\"", "build": "cross-env NODE_ENV=production rspack build", @@ -13,7 +14,8 @@ "format:check": "biome check .", "format:write": "biome format . --write", "lint:check": "biome lint .", - "lint": "biome lint --apply ." + "lint": "biome lint --apply .", + "test": "retest __tests__/*.bs.js" }, "dependencies": { "@emotion/css": "^11.11.2", @@ -29,10 +31,12 @@ "@commitlint/cli": "^17.7.2", "@commitlint/config-conventional": "^17.7.0", "@commitlint/cz-commitlint": "^17.7.2", + "@glennsl/rescript-jest": "^0.10.0", "@rspack/cli": "latest", "@rspack/core": "^0.3.6", "@rspack/plugin-react-refresh": "^0.3.6", "@svgr/webpack": "^8.1.0", + "@testing-library/react": "^14.0.0", "@types/react": "18.2.0", "@types/react-dom": "18.2.1", "commitizen": "^4.3.0", @@ -40,6 +44,9 @@ "cross-env": "^7.0.3", "husky": "^8.0.3", "inquirer": "^9.2.11", + "rescript-js": "^1.0.0-beta.2", + "rescript-nodejs": "^15.0.0", + "rescript-test": "^5.0.0", "typescript": "^5.0.4", "webpack-bundle-analyzer": "^4.9.1" }, diff --git a/rspack.config.js b/rspack.config.cjs similarity index 100% rename from rspack.config.js rename to rspack.config.cjs