From 4a01e6844b2c640c3341263f801f6480eba432e5 Mon Sep 17 00:00:00 2001 From: Joshua Smock Date: Fri, 26 May 2023 14:51:43 +0200 Subject: [PATCH 1/2] Add example_tests folder for easier organic finding of some examples - Fix watch plugin issue related to determining which files to run --- cljest/deps.edn | 3 ++- cljest/example_tests/examples/async_test.cljs | 18 ++++++++++++++++++ .../examples/component_test.cljs} | 2 +- jest-preset-cljest/jest.ns-watch-plugin.js | 12 ++++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 cljest/example_tests/examples/async_test.cljs rename cljest/{src/cljest/example_test.cljs => example_tests/examples/component_test.cljs} (98%) diff --git a/cljest/deps.edn b/cljest/deps.edn index da6a05b..7c88a4b 100644 --- a/cljest/deps.edn +++ b/cljest/deps.edn @@ -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"}}}}} diff --git a/cljest/example_tests/examples/async_test.cljs b/cljest/example_tests/examples/async_test.cljs new file mode 100644 index 0000000..1420878 --- /dev/null +++ b/cljest/example_tests/examples/async_test.cljs @@ -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))))) diff --git a/cljest/src/cljest/example_test.cljs b/cljest/example_tests/examples/component_test.cljs similarity index 98% rename from cljest/src/cljest/example_test.cljs rename to cljest/example_tests/examples/component_test.cljs index 08c48f0..c92873d 100644 --- a/cljest/src/cljest/example_test.cljs +++ b/cljest/example_tests/examples/component_test.cljs @@ -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] diff --git a/jest-preset-cljest/jest.ns-watch-plugin.js b/jest-preset-cljest/jest.ns-watch-plugin.js index a10f5db..6619605 100644 --- a/jest-preset-cljest/jest.ns-watch-plugin.js +++ b/jest-preset-cljest/jest.ns-watch-plugin.js @@ -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 From f748a9aaaf65a81714f4c63838d55e0ebc80f0e4 Mon Sep 17 00:00:00 2001 From: Joshua Smock Date: Fri, 26 May 2023 15:29:32 +0200 Subject: [PATCH 2/2] Update changelog --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index ab30691..89e9763 100644 --- a/changelog.md +++ b/changelog.md @@ -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