This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-22
Channels
- # announcements (6)
- # babashka (8)
- # beginners (136)
- # cider (5)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (198)
- # clojure-argentina (4)
- # clojure-australia (1)
- # clojure-europe (25)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-poland (1)
- # clojure-spec (4)
- # clojure-uk (4)
- # clojuredesign-podcast (4)
- # clojurescript (36)
- # conjure (11)
- # data-science (1)
- # datomic (6)
- # defnpodcast (1)
- # deps-new (5)
- # emacs (7)
- # events (1)
- # fulcro (10)
- # graalvm (9)
- # graalvm-mobile (10)
- # helix (9)
- # introduce-yourself (1)
- # jackdaw (1)
- # jobs-discuss (5)
- # kaocha (6)
- # lsp (10)
- # malli (11)
- # missionary (28)
- # off-topic (2)
- # pathom (24)
- # pedestal (7)
- # portal (1)
- # re-frame (12)
- # reagent (2)
- # reitit (1)
- # remote-jobs (1)
- # sci (7)
- # shadow-cljs (6)
- # sql (6)
- # tools-deps (10)
- # vim (9)
- # xtdb (19)
I'm having a bit of trouble understanding unit tests in re-frame. I've found docs on how to write tests for certain things but not on the basic process of running those tests. I get the impression that there's functionality in the shadow-cljs/re-frame/karma stack to run unit tests automatically on save. Is this correct or am I just looking for something that's not there?
Is that delivered by the :browser-test build target?
Ah, digging in some source on github I'm noticing that build wasn't in the shadow-cljs.edn set up by the template. So I'm guessing if I get that put in (as in https://github.com/day8/re-frame-test/blob/master/project.clj) I'll be able to deftest, save, and see a unit test report appear in the browser?
Right, but note that it will be a separate shadow-cljs process. Better read shadow-cljs documentation on the topic.
Success! Thanks! If you'll permit one more dumb question, where does Karma fit in?
Fair enough. Thanks again!
It has been a while since I've done this but I think the browser-test target will provide a nice browser window showing tests success and re-running them as you make changes to code -- providing a nice TDD workflow.
If I remember right, the karma stuff is how you would want to run tests for CI/CD and is configured a little differently. I could have done things in a non-standard way and this entire conversation might be more appropriate in #shadow-cljs but here is a relevant bit from one of my project's shadow-cljs.edn
:browser-test {:target :browser-test
:test-dir "out"
:ns-regexp "-test$"
:devtools {:http-port 8606
:http-root "out"}}
:test {:target :karma
:output-to "out/karma-test.js"
:ns-regexp "-test$"}
and from my package.json
within the scripts
section
"test": "shadow-cljs compile test && karma start --single-run",
"browser-test": "shadow-cljs watch browser-test"
and lastly my karma.conf.js
module.exports = function(config) {
config.set({
// The directory where the output file lives
basePath: 'out',
browsers: ['ChromeHeadlessNoSandbox'],
client: {
args: ['shadow.test.karma.init'],
singleRun: true
},
colors: true,
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
// The file itself
files: ['karma-test.js'],
frameworks: ['cljs-test'],
logLevel: config.LOG_INFO,
plugins: ['karma-chrome-launcher','karma-cljs-test', 'karma-spec-reporter'],
reporters: ['spec'],
specReporter: {
maxLogLines: 5,
showSpecTiming: true
}
});
};