Skip to content

Commit

Permalink
Merge pull request #33 from pitch-io/example-tests
Browse files Browse the repository at this point in the history
Create example tests directory
  • Loading branch information
jo-sm authored Jun 1, 2023
2 parents 6093b64 + f748a9a commit ffbb628
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

## Improvements
- [Allow aliases to be defined in `cljest.edn` so that Jest can use it when getting the classpath.](https://github.com/pitch-io/cljest/pull/27)
- [Add example tests directory.](https://github.com/pitch-io/cljest/pull/33)

## Bugfixes
- [Always reinstantiate mocks for each test case when using `setup-mocks`.](https://github.com/pitch-io/cljest/pull/28)
- [Fix matcher negation.](https://github.com/pitch-io/cljest/pull/27)
- [Correctly determine the files to run based off of the namespace regex.](https://github.com/pitch-io/cljest/pull/33)


# 1.0.0
Expand Down
3 changes: 2 additions & 1 deletion cljest/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:aliases {:fmt {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}
nsorg-cli/nsorg-cli {:mvn/version "0.3.1"}}}
:publish {:extra-deps {appliedscience/deps-library {:mvn/version "0.3.4"}}}
:test {:extra-deps {com.pitch/uix.core {:mvn/version "0.8.1"}
:test {:extra-paths ["example_tests"]
:extra-deps {com.pitch/uix.core {:mvn/version "0.8.1"}
com.pitch/uix.dom {:mvn/version "0.8.1"}
net.clojars.cyrik/cljs-macroexpand {:mvn/version "0.1.1"}}}}}
18 changes: 18 additions & 0 deletions cljest/example_tests/examples/async_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns examples.async-test
(:require [cljest.core :refer [is it spy]]
[cljest.helpers.core :as h]
[cljest.matchers :as m]))

(defn ^:private fire-async
"Calls given `cb` asynchronously (on the next tick)."
[cb]
(js/process.nextTick cb))

(it "fire-async calls the cb asynchronously"
(let [cb (spy)]
(fire-async cb)
(is (not (m/called? cb)))

(h/async
(await (js/Promise. (fn [res] (js/setTimeout res))))
(is (m/called? cb)))))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljest.example-test
(ns examples.component-test
(:require [cljest.core :refer [before-each describe is it]]
[cljest.helpers.core :as h]
[cljest.helpers.dom :as h.dom]
Expand Down
12 changes: 10 additions & 2 deletions jest-preset-cljest/jest.ns-watch-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,18 @@ class NamespaceWatchPlugin {

return new Promise((resolve, reject) => {
prompt.run((partialNs) => {
const filename = partialNs.replace(/-/g, "_");
const matchedNamespaces = possibleNamespaces.filter((ns) =>
ns.match(partialNs)
);

updateConfigAndRun({
testPathPattern: filename,
testPathPattern: new RegExp(
matchedNamespaces
.map((ns) => ns.replace(/-/g, "_"))
.map((ns) => ns.replace(/\./g, "/"))
.map((ns) => `${ns}.cljs`)
.join("|")
),
});

// see https://jestjs.io/docs/watch-plugins#runglobalconfig-updateconfigandrun. We should explicitly not
Expand Down

0 comments on commit ffbb628

Please sign in to comment.