Skip to content

Commit dc74704

Browse files
committed
feat: add devcards and react testing library
1 parent 015cf3c commit dc74704

File tree

16 files changed

+179
-35
lines changed

16 files changed

+179
-35
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
node_modules
22
dist
33
out
4-
test*
4+
test*/
55
.shadow-cljs
66
.nrepl-port
77
yarn-error.log

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ my-app
6767
| └── favicon.ico
6868
└── src
6969
├── app
70+
| ├── cards
71+
| | ├── devcards_runner.cljs
72+
| | ├── helpers.cljs
73+
| | └── test_runner.cljs
7074
| ├── core.cljs
71-
| └── core_spec.cljs
75+
| ├── hello.cljs
76+
| └── hello_cards.cljs
7277
└── e2e
73-
└── core.cljs
78+
└── core.cljs
7479
```
7580

76-
No configuration or complicated folder structures, just the files you need to build your app.<br>
7781
Once the installation is done, you can open your project folder:
7882

7983
```sh
@@ -94,6 +98,13 @@ You can use existing npm React components directly via a [interop call](http://r
9498
Builds use [Shadow CLJS](https://github.com/thheller/shadow-cljs) for maximum compatibility with NPM libraries. You'll need a [Java SDK](https://adoptopenjdk.net/) (Version 8+, Hotspot) to use it. <br>
9599
You can [import npm libraries](https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps) using Shadow CLJS. See the [user manual](https://shadow-cljs.github.io/docs/UsersGuide.html) for more information.
96100

101+
### `npm run cards` or `yarn cards`
102+
103+
Runs the interactive live development enviroment.<br>
104+
You can use it to design, test, and think about parts of your app in isolation.
105+
106+
This environment uses [Devcards](https://github.com/bhauman/devcards) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro).
107+
97108
### `npm test` or `yarn test`, and `npm run e2e` or `yarn e2e`
98109

99110
`test` launches the test runner in the interactive watch mode.<br>

src/create_cljs_app/template.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Will likely need to be replaced with a proper templating library."
2020
"public/index.html" [{:from "__NAME__" :to name}]
2121
"src/app/core.cljs" [{:from "__NAME__" :to name}]
2222
"README.md" [{:from "__START__" :to (:start commands)}
23+
{:from "__CARDS__" :to (:cards commands)}
2324
{:from "__SERVER__" :to (:server commands)}
24-
{:from "__TEST__" :to (:test commands)}
25-
{:from "__TEST:ONCE__" :to (:test:once commands)}
25+
{:from "__TEST:WATCH__" :to (:test commands)}
26+
{:from "__TEST__" :to (:test:once commands)}
2627
{:from "__E2E__" :to (:e2e commands)}
2728
{:from "__LINT__" :to (:lint commands)}
2829
{:from "__FORMAT__" :to (:format commands)}

src/create_cljs_app/utils.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
[use-yarn]
1414
(if use-yarn
1515
{:start "yarn start"
16+
:cards "yarn cards"
1617
:server "yarn server"
1718
:build "yarn build"
1819
:test "yarn test"
19-
:test:once "yarn test:once"
20+
:test:watch "yarn test:watch"
2021
:e2e "yarn e2e"
2122
:lint "yarn lint"
2223
:format "yarn format"}
2324
{:start "npm start"
25+
:cards "npm run cards"
2426
:server "npm run server"
2527
:build "npm run build"
2628
:test "npm test"
27-
:test:once "npm run test:once"
29+
:test:watch "npm run test:watch"
2830
:e2e "npm run e2e"
2931
:lint "npm run lint"
3032
:format "npm run format"}))

src/e2e/core.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@
3939
(is (not (fileIncludes "./public/index.html" "__NAME__")))
4040
(is (not (fileIncludes "./src/app/core.cljs" "__NAME__")))
4141
(is (not (fileIncludes "./README.md" "__START__")))
42+
(is (not (fileIncludes "./README.md" "__CARDS__")))
4243
(is (not (fileIncludes "./README.md" "__SERVER__")))
4344
(is (not (fileIncludes "./README.md" "__TEST__")))
44-
(is (not (fileIncludes "./README.md" "__TEST:ONCE__")))
45+
(is (not (fileIncludes "./README.md" "__TEST:WATCH__")))
4546
(is (not (fileIncludes "./README.md" "__E2E__")))
4647
(is (not (fileIncludes "./README.md" "__BUILD__")))
4748
(is (not (fileIncludes "./README.md" "__LINT__")))
4849
(is (not (fileIncludes "./README.md" "__FORMAT__"))))
4950
(testing "Commands"
5051
(is (= (.-code (silent-exec "yarn sc start")) 0) "Should start background server")
51-
(is (= (.-code (silent-exec "yarn test:once")) 0) "Should test")
52+
(is (= (.-code (silent-exec "yarn test")) 0) "Should test")
5253
(is (= (.-code (silent-exec "yarn build")) 0) "Should build")
5354
(is (existsSync "./public/js/main.js"))
5455
"Should output public/js/main.js")

template/.clj-kondo/config.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{:lint-as {reagent.core/with-let clojure.core/let}}
1+
{:lint-as {devcards.core/defcard cljs.core/def
2+
devcards.core/deftest cljs.core/def}}

template/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In the project directory, you can run:
66

77
### `__START__`
88

9-
Runs the app in the development mode.<br>
9+
Runs the app in development mode.<br>
1010
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
1111
The page will reload if you make edits.
1212

@@ -16,10 +16,17 @@ You can use existing npm React components directly via a [interop call](http://r
1616
Builds use [Shadow CLJS](https://github.com/thheller/shadow-cljs) for maximum compatibility with NPM libraries. You'll need a [Java SDK](https://adoptopenjdk.net/) (Version 8+, Hotspot) to use it. <br>
1717
You can [import npm libraries](https://shadow-cljs.github.io/docs/UsersGuide.html#js-deps) using Shadow CLJS. See the [user manual](https://shadow-cljs.github.io/docs/UsersGuide.html) for more information.
1818

19+
### `__CARDS__`
20+
21+
Runs the interactive live development enviroment.<br>
22+
You can use it to design, test, and think about parts of your app in isolation.
23+
24+
This environment uses [Devcards](https://github.com/bhauman/devcards) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro).
25+
1926
### `__TEST__` and `__E2E__`
2027

21-
`__TEST__` launches the test runner in the interactive watch mode.<br>
22-
You can use `__TEST:ONCE__` to run the tests a single time, and `__E2E__` to run end-to-end tests.
28+
You can use `__TEST__` to run tests a single time, and `__E2E__` to run the end-to-end test app.
29+
`__TEST:WATCH__` launches tests in interactive watch mode.<br>
2330

2431
See the ClojureScript [testing page](https://clojurescript.org/tools/testing) for more information. E2E tests use [Taiko](https://github.com/getgauge/taiko) to interact with a headless browser.
2532

template/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66
"sc": "shadow-cljs",
77
"server": "shadow-cljs stop && shadow-cljs start",
88
"start": "shadow-cljs watch app",
9+
"cards": "shadow-cljs watch cards",
910
"build": "yarn clean && shadow-cljs release app",
10-
"test": "shadow-cljs watch test --config-merge \"{:autorun true}\"",
11-
"test:once": "shadow-cljs compile test && node out/test.js",
11+
"test": "shadow-cljs compile test && node out/test.js",
12+
"test:watch": "shadow-cljs watch test --config-merge \"{:autorun true}\"",
1213
"e2e": "shadow-cljs compile e2e && node out/e2e.js",
1314
"lint": "clj-kondo --lint src",
1415
"format": "zprint-clj --hang -i \"./src/**/*.{clj,cljs,cljc,edn}\" -o ./ && zprint-clj -i \"./*.edn\" -o ./",
1516
"clean": "rimraf public/js"
1617
},
1718
"devDependencies": {
19+
"@testing-library/dom": "^6.10.1",
20+
"@testing-library/react": "^9.3.2",
1821
"clj-kondo": "2019.11.23",
22+
"highlight.js": "9.15.10",
23+
"jsdom": "^15.2.1",
24+
"jsdom-global": "^3.0.2",
25+
"marked": "^0.7.0",
1926
"rimraf": "~3.0.0",
2027
"serve-handler": "~6.1.2",
2128
"shadow-cljs": "~2.8.74",
@@ -25,7 +32,7 @@
2532
},
2633
"dependencies": {
2734
"create-react-class": "~15.6.3",
28-
"react": "~16.12.0",
29-
"react-dom": "~16.12.0"
35+
"react": "~16.8.0",
36+
"react-dom": "~16.8.0"
3037
}
3138
}

template/shadow-cljs.edn

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
:modules {:main {:init-fn app.core/main}}
44
:output-dir "public/js"
55
:target :browser}
6+
:cards {:asset-path "/js"
7+
:modules {:main {:init-fn app.cards.devcards-runner/main}}
8+
:compiler-options {:devcards true}
9+
:output-dir "public/js"
10+
:target :browser}
11+
:test {:main app.cards.test-runner/main
12+
:output-to "out/test.js"
13+
:target :node-test}
614
:e2e {:ns-regexp "e2e.*"
715
:output-to "out/e2e.js"
8-
:target :node-test}
9-
:test {:ns-regexp "app.*-spec$"
10-
:output-to "out/test.js"
11-
:target :node-test}}
12-
:dependencies [[reagent "0.8.1"]]
16+
:target :node-test}}
17+
:dependencies [[reagent "0.8.1"]
18+
[devcards "0.2.6"]]
1319
:dev-http {3000 "public"}
1420
:nrepl {:port 3333}
1521
:source-paths ["src"]}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(ns app.cards.devcards-runner
2+
(:require [cljsjs.react]
3+
[cljsjs.react.dom]
4+
; devcards needs cljsjs.react and cljsjs.react.dom to be imported
5+
; separately for shadow-cljs to add shims.
6+
[devcards.core :refer [start-devcard-ui!]]
7+
; Import all namespaces with cards here to load them.
8+
[app.hello-cards]))
9+
10+
(defn ^:export main
11+
"Start the devcards UI."
12+
[]
13+
; Add a special class to the body to signal we're in devcards mode.
14+
; We want to mostly use the same styles as the app, but might need to make
15+
; some exceptions.
16+
(js/document.body.classList.add "using-devcards")
17+
; Start the devcards UI.
18+
(start-devcard-ui!))

0 commit comments

Comments
 (0)