Skip to content

Commit e8851ed

Browse files
committed
feat: simplify devcards setup
1 parent 0325010 commit e8851ed

File tree

6 files changed

+17
-44
lines changed

6 files changed

+17
-44
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ my-app
6767
| └── favicon.ico
6868
└── src
6969
├── app
70-
| ├── cards
71-
| | ├── devcards_runner.cljs
72-
| | ├── helpers.cljs
73-
| | └── test_runner.cljs
70+
| ├── cards.cljs
7471
| ├── core.cljs
7572
| ├── hello.cljs
7673
| └── hello_cards.cljs

template/shadow-cljs.edn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
:output-dir "public/js"
55
:target :browser}
66
:cards {:asset-path "/js"
7-
:modules {:main {:init-fn app.cards.devcards-runner/main}}
7+
:modules {:main {:init-fn app.cards/main}}
88
:compiler-options {:devcards true}
99
:output-dir "public/js"
1010
:target :browser}
11-
:test {:main app.cards.test-runner/main
11+
:test {:ns-regexp "app.cards"
1212
:output-to "out/test.js"
1313
:target :node-test}
1414
:e2e {:ns-regexp "e2e.*"

template/src/app/cards/devcards_runner.cljs renamed to template/src/app/cards.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
(ns app.cards.devcards-runner
1+
(ns app.cards
22
(:require [cljsjs.react]
33
[cljsjs.react.dom]
44
; devcards needs cljsjs.react and cljsjs.react.dom to be imported
55
; separately for shadow-cljs to add shims.
66
[devcards.core :refer [start-devcard-ui!]]
7+
["jsdom-global" :as jsdom-global]
78
; Import all namespaces with cards here to load them.
89
[app.hello-cards]))
910

11+
; Set jsdom to mock a dom environment for node testing.
12+
(jsdom-global)
13+
1014
(defn ^:export main
1115
"Start the devcards UI."
1216
[]

template/src/app/cards/helpers.cljs

Lines changed: 0 additions & 9 deletions
This file was deleted.

template/src/app/cards/test_runner.cljs

Lines changed: 0 additions & 26 deletions
This file was deleted.

template/src/app/hello_cards.cljs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
[devcards.core :as dc :refer [defcard deftest]]
44
[cljs.test :include-macros true :refer [is]]
55
["@testing-library/react" :refer [render cleanup fireEvent]]
6-
[app.hello :refer [click-counter hello]]
7-
[app.cards.helpers :refer [testing-container]]))
6+
[app.hello :refer [click-counter hello]]))
7+
8+
(defn testing-container
9+
"The container that should be used to render testing-library react components.
10+
We want to provide our own container so that the rendered devcards aren't used."
11+
[]
12+
(let [app-div (js/document.createElement "div")]
13+
(.setAttribute app-div "id" "testing-lib")
14+
(js/document.body.appendChild app-div)))
815

916
(defcard
1017
"This is a live interactive development environment using [Devcards](https://github.com/bhauman/devcards).

0 commit comments

Comments
 (0)