Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ jobs:

example:
runs-on: ubuntu-latest
strategy:
matrix:
example: [reagent-karma-example, node-test-example]
defaults:
run:
working-directory: examples/reagent-karma-example
working-directory: examples/${{ matrix.example }}
steps:
- uses: actions/checkout@v4

Expand All @@ -52,10 +55,7 @@ jobs:
with:
node-version: 22
cache: npm
cache-dependency-path: examples/reagent-karma-example/package-lock.json
cache-dependency-path: examples/${{ matrix.example }}/package-lock.json

- run: npm ci
- run: npm run fmt:check
- run: npm run lint
- run: npx shadow-cljs compile app
- run: npm test
- run: npm run ci
4 changes: 4 additions & 0 deletions examples/node-test-example/.clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;; `await` is the native ClojureScript async operator (cljs >= 1.12.145).
;; The clj-kondo release on npm does not recognize it yet, so silence the
;; unresolved-symbol warning for it here.
{:linters {:unresolved-symbol {:exclude [await]}}}
7 changes: 7 additions & 0 deletions examples/node-test-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
/out
/target
/.shadow-cljs
/.cpcache
/.clj-kondo/.cache
/.clj-kondo/imports
5 changes: 5 additions & 0 deletions examples/node-test-example/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
out
target
.shadow-cljs
.cpcache
3 changes: 3 additions & 0 deletions examples/node-test-example/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["prettier-plugin-cljfmt"]
}
31 changes: 31 additions & 0 deletions examples/node-test-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# node-test-example

A minimal example of testing ClojureScript components with
[`react-testing-library-cljs`](https://github.com/olecve/react-testing-library-cljs)
using shadow-cljs's `:node-test` target and [jsdom](https://github.com/jsdom/jsdom) —
no browser required. This is the simplest setup and runs end to end in CI.

## What it demonstrates

- **`app.reagent-test`** — testing Reagent components: `render!`, `fire-event`
(wrapped in `act`), `screen` queries, scoped queries with `within`, and mock
handlers via `mocks/create`.
- **`app.plain-react-test`** — testing plain React (no Reagent) with raw
`react/createElement`, `user-event`, and async `find-by-*` queries written as
native `^:async` / `await` tests.

## Setup essentials

- `shadow-cljs.edn` declares `reagent` and the library as `:dependencies` and a
`:node-test` build with an `app.test-setup` preload.
- `src/app/test_setup.cljs` registers jsdom (`global-jsdom/register`) and sets
`IS_REACT_ACT_ENVIRONMENT`, giving the tests a DOM and reliable React updates.

## Running

```bash
npm install
npm test # compile the :test build and run it on Node
npm run lint # clj-kondo
npm run fmt # prettier + cljfmt
```
Loading
Loading