Add testing library and document workflow

Also moved testing instruction to dev-practices as it didn't make sense
to have them split
This commit is contained in:
Gabriel Horner
2022-02-22 16:47:04 -05:00
committed by Andelf
parent b0babf2232
commit 163d31005f
3 changed files with 37 additions and 23 deletions

View File

@@ -43,6 +43,7 @@
:test {:extra-paths ["src/test/"]
:extra-deps {org.clojure/clojurescript {:mvn/version "1.10.879"}
org.clojure/test.check {:mvn/version "1.1.1"}
org.clojars.lucywang000/shadow-test-utils {:mvn/version "0.0.2"}
org.clojars.knubie/cljs-run-test {:mvn/version "1.0.1"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]}

View File

@@ -53,12 +53,41 @@ To configure the linter, see its `config` var.
## Testing
We have unit and end to end tests as described in https://github.com/logseq/logseq#5-run-tests.
We have unit and end to end tests.
### End to End Tests
To run end to end tests
``` bash
yarn electron-watch
# in another shell
yarn e2e-test # or npx playwright test
```
### Unit Testing
When writing unit tests it is helpful to have tests automatically run on file
save with `yarn shadow-cljs watch test --config-merge '{:autorun true}'`. The
test output may appear where shadow-cljs was first invoked e.g. where `yarn
watch` is running. For more about the shadow-cljs test runner, see [this
documentation](https://shadow-cljs.github.io/docs/UsersGuide.html#_testing).
Our unit tests use the [shadow-cljs test-runner](https://shadow-cljs.github.io/docs/UsersGuide.html#_testing). To run them:
```bash
yarn test
```
There are a couple different ways to develop with tests:
#### Autorun Tests
To run tests automatically on file save, run `yarn
shadow-cljs watch test --config-merge '{:autorun true}'`. The test output may
appear where shadow-cljs was first invoked e.g. where `yarn watch` is running.
Specific namespace(s) can be auto run with the `:ns-regexp` option e.g. `npx
shadow-cljs watch test --config-merge '{:autorun true :ns-regexp
"frontend.text-test"}'`.
#### Focus Tests
Tests can be automatically compiled and then selectively run on the commandline
using https://github.com/lucywang000/shadow-test-utils. For this workflow:
1. Run `clj -M:test watch test` in one terminal
2. Focus a test by adding a `^:focus` metadata flag
3. In another terminal, run `node node static/tests.js`

View File

@@ -23,22 +23,6 @@ Open <http://localhost:3001>.
yarn release
```
### 5. Run tests
Run ClojureScript tests
```bash
yarn test
```
Run E2E tests
``` bash
yarn electron-watch
# in another shell
yarn e2e-test # or npx playwright test
```
## Desktop app development
### 1. Compile to JavaScript
@@ -63,4 +47,4 @@ yarn dev-electron-app
```bash
yarn release-electron
```
```