This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-16
Channels
- # aleph (1)
- # announcements (16)
- # babashka (36)
- # beginners (62)
- # calva (15)
- # cider (21)
- # cljsrn (5)
- # clojure (84)
- # clojure-dev (3)
- # clojure-europe (22)
- # clojure-italy (2)
- # clojure-nl (2)
- # clojure-uk (3)
- # clojurescript (36)
- # core-async (2)
- # cursive (4)
- # datomic (8)
- # emacs (14)
- # events (1)
- # fulcro (4)
- # hyperfiddle (6)
- # introduce-yourself (3)
- # jobs (1)
- # leiningen (4)
- # lsp (100)
- # nrepl (3)
- # off-topic (36)
- # pathom (17)
- # podcasts (1)
- # polylith (4)
- # portal (14)
- # react (1)
- # reagent (3)
- # reitit (8)
- # releases (3)
- # remote-jobs (1)
- # reveal (7)
- # shadow-cljs (19)
- # sql (16)
- # web-security (3)
I am a long-time user of re-frame and now wanted to try to the Karma-integration with cljs.test. Just created new project from the re-frame template with +test:
lein new re-frame verto_gui +garden +10x +test
Then, according to the instructions in the README.md, started auto-reload and karma in another cmd:
npm install
npm run watch
...
karma start
I see the tests being executed ok:
Chrome Headless 99.0.4844.51 (Windows 10) verto-gui.core-test fake-test FAILED
FAIL in (fake-test) (verto_gui/core_test.cljs:7:9)
"fake description"
expected: (=
...
However, when I make any change to the core_tests.cljs, eg. editing "fake description" to "fake description 2", the subsequent reload produces error:
16 03 2022 09:29:47.135:INFO [filelist]: Changed file "C:/dev/verto_gui/target/karma-test.js".
(node:5640) [log4js-node-DEP0004] DeprecationWarning: Pattern %d{DATE} is deprecated due to the confusion it causes when used. Please use %d{DATETIME} instead.
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: missing ) after argument list
at karma-test.js:33653:588
I wonder if there is something I can do to prevent this? Or is this some bug in the framework? Since this happens with completely vanilla re-frame project from the template, it should be easily reproduced if someone is interested.Are you sure the file you saved has all ()
paired? Because the error certainly looks like there are more (
than there are )
. And I cannot reproduce that error by making a proper change to the file.
Although, that error is not a compilation one, so it's probably not about balancing CLJS parens...
As a guess, it could've been a race condition if the JS bundle is written to disk gradually. So the compiler starts writing JS, Karma detects the change and loads the file - all while that JS is still being written.
With some additional tries, there seems to be indeed some randomness. On most tries I get the same error about parenthesis, occasionally another syntax error:
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: Unexpected end of input
at karma-test.js:47546:3
SyntaxError: Unexpected end of input
And indeed in some cases works also without error. So could be race-condition that is surfacing on the specific timing characteristics of my system
Just in case - even though Slack embeds a preview of that message, you should still follow that link as there's a workaround posted right below the message.
I tried setting autoWatchBatchDelay to high value (10000 ie 10 secs) but in this case it does not seem to resolve the problem.
16 03 2022 12:27:19.815:INFO [filelist]: Changed file "C:/dev/verto_gui/target/karma-test.js".
(node:12476) [log4js-node-DEP0004] DeprecationWarning: Pattern %d{DATE} is deprecated ...
**** 10 sec delay here ****
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: Invalid or unexpected token
at karma-test.js:43396:1
SyntaxError: Invalid or unexpected token
The locations and types of syntax errors still vary randomly but inspecting karma-test.js shows no visible errors at the reported location.To eliminate possible sources from dangling processes and IDE (I use IntelliJ + Cursive) I rebooted and started the build with minimal environment and no IDE. With the "npm run watch" and "karma start" running I get from subsequent minimal modifications to the test-code still errors at random locations:
16 03 2022 12:47:18.458:INFO [filelist]: Changed file "C:/dev/verto_gui/target/karma-test.js".
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: Unexpected end of input
at karma-test.js:15043:19
SyntaxError: Unexpected end of input
16 03 2022 12:47:38.697:INFO [filelist]: Changed file "C:/dev/verto_gui/target/karma-test.js".
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: Unexpected end of input
at karma-test.js:10802:25
SyntaxError: Unexpected end of input
16 03 2022 12:47:53.410:INFO [filelist]: Changed file "C:/dev/verto_gui/target/karma-test.js".
Chrome Headless 99.0.4844.51 (Windows 10) ERROR
Uncaught SyntaxError: Unexpected end of input
at karma-test.js:19463:1
SyntaxError: Unexpected end of input
No clue. Found another relevant thing though: https://github.com/karma-runner/karma/issues/2420#issuecomment-300652948
Also here and below, even though it mentions Linux: https://github.com/karma-runner/karma/issues/1113#issuecomment-50381150
Thanks for the suggestions @U2FRKM4TW! At least we have some understanding on the nature of the issue now. I am using Windows 11, but perhaps there are similar caching issues
Pity the problem does not reproduce as readily with other users as I thought, but I understand that timing-related issues can depend in a subtle way on the characteristics of ones computer, OS, etc
In addition, that's something that other users might not even be using at all. E.g. my UI tests are run with shadow-cljs during local development. And even if I were using Karma for CI, it would not be a problem as well because there wouldn't be any watchers, thus no chance of race conditions.
Ah! The usePolling: true seems to fix the problem for me! 😀 This was hinted by the second link https://github.com/karma-runner/karma/issues/1113#issuecomment-50381150 . Although the text there suggested that Karma reverted to the polling as the default behavior, perhaps they have re-reverted to events later and therefore usePolling: true can still help (although that parameter does not seem to be even documented at http://karma-runner.github.io/6.3/config/configuration-file.html ) Thanks even more!
Would it be possible to connect the REPL to a production CLJS app? https://twitter.com/simonelnahas/status/1504058143315308544
> to e.g. emit re-frame events? If you have a very narrow scope of what you want to do in such a REPL, you can simply define and export it as a set of CLJS functions that you would then be able to call from JS.
Say I have a server rendered Hiccup site, and would like to add two different CLJS scripts to two different pages. Is it possible to generate JS output in such a way that all the code that's common to both scripts are in one file, and the page-specific parts are in separate files?
This would allow me to load and cache common.js
on both pages, meaning faster load time for the other page.
https://code.thheller.com/blog/shadow-cljs/2019/03/03/code-splitting-clojurescript.html
I have a function that performs a slow computation and returns some data. How can I make this function run at compile-time instead of at runtime? Running it in Clojure is fine, so I suppose I should be able to wrap it in a macro?
How would I actually do that though?
just doing (def my-macro [] (my-fn))
and (def my-data (my-macro))
doesn't seem to work
cool thx
@U15RYEQPJ What you did above should almost work. Have you tried (defmacro my-macro [] (my-fn))
?
yeah thanks, I managed to get it working