kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
defa 2020-03-10T07:59:32.044600Z

I have a shadow-cljs based react-native project and I’d like to run some tests with kaocha however I’m getting this error:

$ clj -A:test --no-capture-output
[TypeError: Cannot read property 'error__GT_str' of undefined
    at Socket.<anonymous> ([stdin]:89:38)
    at Socket.emit (events.js:321:20)
    at Socket.EventEmitter.emit (domain.js:485:12)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:214:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

E]
Any ideas what that might cause? I tested my configuration in a minimal project and it works. After the E] the process keeps running with no output. UPDATE: this error only happens when having thheller/shadow-cljs {:mvn/version "2.8.90"} as a dependency in deps.edn. SOLVED: making use of an additional tools.deps alias solved the problem by not having shadow-cljs on the test classpath. Thanks for reading and sorry for the noise πŸ˜‰

plexus 2020-03-10T08:34:26.047300Z

hey @dharrigan thanks for reporting this, I also assumed that defexpect would just work, but they are probably using custom event types which the reporter needs to know about. Not a lot of work and something we can add support for without directly having to have expectations as a dependency

dominicm 2020-03-10T08:34:38.047700Z

I don't think #ref will be able to work inside of a #kaocha/v1 btw. Aero is unable to figure out the expected ordering.

dharrigan 2020-03-10T08:34:57.048200Z

Thanks @plexus that would be nice!

plexus 2020-03-10T08:36:33.049700Z

Not saying I'm gonna do it πŸ™‚ got a lot of things competing for my time right now, but if you file an issue I'll pitch in with what needs to happen. Would be helpful if you could run with --reporter kaocha.report/debug, and look what values the :type keys have

dharrigan 2020-03-10T08:37:33.050600Z

no problemo πŸ™‚ I'll get on to that too

plexus 2020-03-10T08:38:27.051500Z

@flowthing never looked into it, I agree those stacktraces aren't great. Kaocha's stacktraces in general could be much improved. Would be useful to file an issue on kaocha-cljs to track this.

flowthing 2020-03-12T10:21:59.117400Z

All right, good to know, thanks. I'll file that issue.

flowthing 2020-03-12T11:31:35.117600Z

https://github.com/lambdaisland/kaocha-cljs/issues/30

plexus 2020-03-13T08:28:28.118Z

thanks!

plexus 2020-03-10T08:39:44.052700Z

@dominicm that makes sense. Note that #kaocha/v1 is really just a convenience, you should be able to do kaocha --print-config > tests.edn.new and go from there (cleaning a few things up, notably the current cli arguments)

plexus 2020-03-10T08:40:44.054300Z

it's more verbose, many more namespaced keys, and all defaults need to be filled in explicitly, but it's not a terrible format to work with

dominicm 2020-03-10T08:40:58.054700Z

Yeah. That's one solution. You might also want to make kaocha/v1 a aero macro, that would give it control over how things are resolved inside of itself. Haven't thought about how you'd write that yet though.

plexus 2020-03-10T08:42:50.055700Z

it's already being handled by aero though, right? does it have a separate concept of "macros"?

dominicm 2020-03-10T08:42:50.055800Z

Gonna expand for now, but might be one to ponder if this comes up again :)

dominicm 2020-03-10T08:44:13.058100Z

Aero has reader "functions" (normal ones) and reader macros (like #profile and #ref). The macros can do special things like case, etc

plexus 2020-03-10T08:44:41.058500Z

@defa great to hear you got that working! shadow-cljs is not terribly well supported right now. If your code is compatible with standard clojurescript then you're all good, but if you use shadow-specific compiler extensions you may be out of luck

plexus 2020-03-10T08:45:29.059700Z

@dominicm I see, I guess it gets expanded at an earlier stage. Are there any downsides/risks to switching? anything that would behave differently? seems like a no-brainer to just go ahead with

defa 2020-03-10T08:48:18.061800Z

@plexus no, there is no complier magic going on, just shadow-cljs on the classpath and a minimal test (is false). To clarify I’m not running the tests via shadow-cljs at all but separate via clj.

dominicm 2020-03-10T08:52:46.061900Z

You'd have to think a bit harder to have it work. Presumably users want their tags to expand without #kaocha/v1 having expanded. That's probably the easiest version. Essentially as if their map was the config file itself. The complex version involves trying to expand, then trying to add in the expanded keys if possible, then trying to continue.

dominicm 2020-03-10T08:52:54.062100Z

Essentially, it's more code :)

plexus 2020-03-10T08:54:40.062300Z

ok, in that case it's for future consideration πŸ™‚

defa 2020-03-10T09:12:42.063700Z

Any ideas why there is no output captured even if I pass --no-capture-output to the rest runner? My test fails and starts with:

(deftest foo
  (println "Hello!")
  ...)

plexus 2020-03-10T09:34:00.064500Z

that's not enough context @defa... what does your tests.edn look like? can you create a minimal reproduction?

defa 2020-03-10T09:38:07.064600Z

Sure…

;; tests.edn
#kaocha/v1
    {:tests [{:id           :unit-cljs
              :type         :kaocha.type/cljs
              :test-paths   ["src/test"]
              :ns-patterns  ["-test$"]
              }]
     }

defa 2020-03-10T09:38:22.064800Z

;; deps.edn
{:deps  {}
 :paths ["src/main" "src/test"]
 :aliases
        {:test
         {:extra-deps {lambdaisland/kaocha      {:mvn/version "0.0-590"}
                       lambdaisland/kaocha-cljs {:mvn/version "0.0-71"}}
          :main-opts  ["-m" "kaocha.runner"]}}}

defa 2020-03-10T09:38:30.065Z

(ns foo.foo-test
  (:require [clojure.test :refer [deftest testing is are]]))

(deftest fail
  (println "hello!")
  (testing "will fail"
    (is false "failed by intention")))

dharrigan 2020-03-10T09:54:15.065400Z

Hi @plexus I saw your comment. I think I can do that πŸ™‚

defa 2020-03-10T09:58:41.065500Z

@plexus I can upload a repo to gihub if that helps? Otherwise the relevant parts above.

plexus 2020-03-10T10:04:30.065700Z

ok, so this is for clojurescript tests using node?. I would run with the debug options and see if you see any stdout messages coming back from the JS runtime. One possible explanation would be that the process exits before we receive the stdout. Do you see printlns outside the deftest?

defa 2020-03-10T10:12:48.065900Z

Nope, println outside of deftest does not show up. Which debug options do you mean?

defa 2020-03-10T10:15:21.066100Z

(js/console.log "...") does produce some output, inside and outside of deftest but not in an ASCII art β€˜box’.

defa 2020-03-10T10:17:20.066300Z

… and yes, this is ClojureScript and I suppose node is involved in the background. I’m testing code that usually gets compiled by shadow-cljs with a react-native target.

plexus 2020-03-10T10:39:53.066500Z

there are debug instructions in the kaocha-cljs README, which should produce some very verbose output.

plexus 2020-03-10T10:40:26.066700Z

> (js/console.log "...") does produce some output, inside and outside of deftest but not in an ASCII art β€˜box’. Maybe you just need an (enable-console-print!)

defa 2020-03-10T10:50:37.066900Z

@plexus okay, that helps :thumbsup:

defa 2020-03-10T10:51:08.067100Z

However it does not look like in the docs:

FAIL in sample-test/stdout-fail-test (sample_test.clj:10)
Expected:
  :same
Actual:
  -:same +:not-same
╭───── Test output ───────────────────────────────────────────────────────
β”‚ Bu yi le hu?
╰─────────────────────────────────────────────────────────────────────────
2 tests, 2 assertions, 1 failures.
… but I’m okay with that.

defa 2020-03-10T10:51:43.067300Z

The β€œTest output” ASCII-frame is missing.

plexus 2020-03-10T10:53:15.067500Z

is that with or without output capturing? you'll only get the frame when output capturing is on

dharrigan 2020-03-10T11:02:23.068100Z

@plexus is it reasonable to pull in expectations in the test alias (in deps.edn) for kaocha so that I can test the =? macro?

plexus 2020-03-10T11:06:54.068500Z

I guess that's acceptable. How big is it?

plexus 2020-03-10T11:06:59.068700Z

What does =? do?

dharrigan 2020-03-10T11:19:26.069300Z

6.5K Mar 3 13:44 clojure-test-1.2.1.jar

dharrigan 2020-03-10T11:19:40.069700Z

under 7KB πŸ™‚

dharrigan 2020-03-10T11:19:56.069900Z

❯ unzip -l clojure-test-1.2.1.jar                        
Archive:  clojure-test-1.2.1.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2019-12-09 09:41   expectations/
        0  2019-12-09 09:41   expectations/clojure/
    13888  2019-12-09 09:17   expectations/clojure/test.clj
        0  2019-12-09 09:41   META-INF/
       57  2019-12-09 09:41   META-INF/MANIFEST.MF
        0  2019-12-09 09:41   META-INF/maven/
        0  2019-12-09 09:41   META-INF/maven/expectations/
        0  2019-12-09 09:41   META-INF/maven/expectations/clojure-test/
      114  2019-12-09 09:41   META-INF/maven/expectations/clojure-test/pom.properties
     1895  2019-12-09 09:41   META-INF/maven/expectations/clojure-test/pom.xml
---------                     -------
    15954                     10 files

plexus 2020-03-10T11:20:35.070200Z

yeah that's fine

dharrigan 2020-03-10T11:24:21.070400Z

np

dharrigan 2020-03-10T11:24:25.070700Z

ta

dominicm 2020-03-10T11:28:56.072200Z

Would it make sense for kaocha.report/fail-summary to look at t/testing-contexts if there's none in the message? They're only in the message from :summary

dominicm 2020-03-10T11:29:33.072700Z

And that's because kaocha.history puts it there

plexus 2020-03-10T12:09:05.073Z

what's the use case/problem statement @dominicm ?

defa 2020-03-10T12:12:21.073100Z

I run kaocha like this:

clj -A:test --watch --no-capture-output
… oh shit… I’m so stupid… sorry. I misunderstood the semantics of the command line option πŸ™ˆ

defa 2020-03-10T12:14:27.073600Z

@plexus works just fine.

dominicm 2020-03-10T12:14:40.074Z

Kaocha isn't picking up that some of my tests have meta when using focus-meta. I'd like to debug why. The printed plan is way too big. What else can I look at?

dominicm 2020-03-10T12:15:17.074100Z

I'm writing a custom reporter, and I want to include details about the failure when it happens, as opposed to during the summary. This report has to be this format due to CI constraints.

dominicm 2020-03-10T12:16:11.074600Z

I've run the kaocha.load stuff that kaocha clojure test does, and I can see that kaocha has found the metadata on the tests, so I'm doubly confused :(

plexus 2020-03-10T12:16:28.075Z

Maybe poke at it from a REPL? (kaocha.repl/test-plan), then filter as needed

defa 2020-03-10T12:17:03.075600Z

Sorry if I was wasting your time… too much work to few sleep.

plexus 2020-03-10T12:17:09.075900Z

do you have other focus/skip config? maybe they're interacting in unexpected ways

dominicm 2020-03-10T12:17:57.077100Z

All of my test groups have a focus/skip. One of them has skip set to all of the other metadatas

plexus 2020-03-10T12:18:39.077400Z

with test group do you mean test suite?

plexus 2020-03-10T12:19:09.078200Z

and do you have test suites that have the same test-paths but are differentiated by skip/focus?

dominicm 2020-03-10T12:19:09.078300Z

Yes, probably :)

dominicm 2020-03-10T12:19:16.078500Z

Yep, that's exactly right.

plexus 2020-03-10T12:19:32.078900Z

ok, that's an anti-pattern and will not work as you would expect

defa 2020-03-10T12:20:17.080200Z

… even without (enable-console-print!)

dominicm 2020-03-10T12:20:20.080500Z

Will read before I ask my next question

plexus 2020-03-10T12:21:09.081300Z

one problem with this is that the same test-id will occur multiple times in the test plan, we should really have a warning for that, as that will confuse plugins like the filtering plugin

dominicm 2020-03-10T12:22:10.082700Z

That would solve my problem of wanting to make the groups explicitly, especially as I want to define an "inverse" (not :external, not :integration, not :devcards...)

dominicm 2020-03-10T12:23:28.084Z

The problem is that for me, unit tests are "the ones that aren't the others"

plexus 2020-03-10T12:23:42.084100Z

yeah, wouldn't be exceptionally hard to implement either... I'm guesing a ~100 line plugin

plexus 2020-03-10T12:24:15.084700Z

although the real recommendation would be to split your tests on the filesystem test/unit/ / test/integration etc

dominicm 2020-03-10T12:25:06.085500Z

Not sure about getting buy in for that right now. The task would be difficult.

dominicm 2020-03-10T12:25:44.086600Z

I quite like the idea of having a mega suite, and just defining selectors on it. It's probably impractical, but has a good hierarchy in my brain.

defa 2020-03-10T12:30:01.086700Z

… but not always. In my real project

(enable-console-print!)
is necessary even without --no-capture-output

dominicm 2020-03-10T12:30:31.087500Z

This does explain why you run all tests if no focus meta matches. I was getting really annoyed with that :)

dominicm 2020-03-10T12:32:27.088200Z

Hmm, that would still be useful for running a group of tests across suites. Eg run all unit tests, if there's none in cljs then it doesn't matter.

plexus 2020-03-10T12:33:29.089200Z

If I put together a PoC would you be able to get a little contribution going on the opencollective?

dominicm 2020-03-10T12:34:20.090600Z

I did start floating the idea at the client about that. But they're still figuring out how to let people contribute bug fixes to oss.

plexus 2020-03-10T12:35:04.091Z

just to be clear I'm talking about a monetary contribution, not a code contribution

dominicm 2020-03-10T12:35:52.092300Z

I know. Sorry, I was trying to point out that they all haven't solved the problem of that. They are totally unprepared for funding.

plexus 2020-03-10T12:36:04.092500Z

I see... too bad

plexus 2020-03-10T12:37:08.093200Z

in that case I would consider adding a plugin inside the project and doing it yourself, you can use the filter plugin for inspiration

plexus 2020-03-10T12:37:46.093800Z

it's really just recursively walking the test-plan, and marking testables as :kaocha.testable/skip true or not

dominicm 2020-03-10T12:38:26.094700Z

Yeah. Makes sense. I might just inflict a very long cli on people in the meantime..

plexus 2020-03-10T12:38:37.094900Z

that also works

dominicm 2020-03-10T12:39:51.095700Z

Just to check, is it okay for two suites (clj/cljs) to have overlapping paths?

plexus 2020-03-10T12:43:03.096200Z

clj / cljs is fine because the ids are different, the cljs testables are prefixed with cljs:

plexus 2020-03-10T12:43:31.096800Z

so it's fine to e.g. have a single directory with cljc files and consider that to be two test suites, one clj one cljs

plexus 2020-03-10T12:44:35.096900Z

> Sorry if I was wasting your time… No problem at all! I like to make sure people are able to make the best of Kaocha

dominicm 2020-03-10T12:46:48.097700Z

Ah, great. That's one worry gone.

dominicm 2020-03-10T12:47:17.097800Z

They can print at the end too. But my error reporter needs to print context.

plexus 2020-03-10T12:48:36.098Z

and so you're calling fail-summary from your reporter on for instance a :fail event?

dominicm 2020-03-10T12:49:48.098200Z

Yep!

plexus 2020-03-10T12:49:58.098400Z

I would suggest putting :testing-contexts in the map when you call it, rather than the other way around

dominicm 2020-03-10T12:50:36.098600Z

That's what I'm doing for now, although it did feel like reaching as implementation details.

plexus 2020-03-10T12:51:18.098800Z

building kaocha's reporting on top of clojure.test is one of the few things I regret. It really should be a separate adapter layer that knows about these clojure.test vars and makes the messages self-contained

plexus 2020-03-10T12:51:27.099Z

so that's the direction in general I would prefer to move to

plexus 2020-03-10T12:52:24.099200Z

so think of it as kaocha's reporting API, where the messages are a generalization of clojure.test's messages

dominicm 2020-03-10T12:57:29.099400Z

Heh, okay :) I guess everywhere else would be using the api wrong by not providing those keys?

dominicm 2020-03-10T14:02:41.099900Z

Can I disable the assertion exceptions?

dominicm 2020-03-10T14:03:05.100400Z

I have a particular test which doesn't make assertions yet.

plexus 2020-03-10T14:11:02.101300Z

we don't have a setting for that (yet), adding a dummy assertion is not an option?

plexus 2020-03-10T14:11:21.101700Z

the other option is removing this association from the hierarchy (derive! :kaocha.type.var/zero-assertions :kaocha/fail-type)

plexus 2020-03-10T14:11:48.102200Z

and redefining the report/fail-summary to do nothing

plexus 2020-03-10T14:12:13.102500Z

(defmethod report/fail-summary :kaocha.type.var/zero-assertions [{:keys [testing-contexts testing-vars] :as m}])

dominicm 2020-03-10T14:18:57.103Z

It is, just wanted to check before I checked 1=1.

dominicm 2020-03-10T14:19:57.104600Z

Unrelated, the missing assertion test seems to be happening for a case which very obviously has assertions. My best guess is that the test is clojurescript async, and that isn't being handled. But I'm not certain at all. Anything ring a bell?

dominicm 2020-03-10T14:20:50.106Z

Sorry, I have lots of questions today. Our test suite is apparently not in the state kaocha expects.

dominicm 2020-03-10T14:22:00.106300Z

Test isn't async, so not that!

plexus 2020-03-10T14:32:11.107Z

ah it's a clojurescript test? although I guess same advice applies, as it piggiebacks on the event type and defmethod created by kaocha.type.var

plexus 2020-03-10T14:32:37.107500Z

questions very welcome! it's good to know what is or isn't working for people, or what isn't clear or obvious

plexus 2020-03-10T14:33:48.108700Z

and yeah when bringing on a big legacy test suite you're going to run into some things like this because kaocha is more strict about certain things (because it tries to prevent you from accidentally doing things you didn't intended). We really should have flags to disable these things to make porting to kaocha easier.

πŸ‘ 1
plexus 2020-03-10T14:42:27.110600Z

yeah not sure what else would be triggering ::zero-assertions. Run the test with the debugging enabled and see what events you're getting (--focus on just that test). I would expect you are not seeing any assertions over the wire before the test finishes, in which case the question is why the test/runtime behave that way. If you are seeing assertions over the wire then the question is why kaocha.type.cljs still thinks that (= pass error fail pending 0)

dominicm 2020-03-10T14:51:25.111400Z

Figured it out. We have a namespace which runs tests as a top level side effect. I'm guessing they were running in parallel

plexus 2020-03-10T14:53:17.111700Z

oh yeah that would explain it

dharrigan 2020-03-10T15:03:42.112200Z

@plexus I hope the commit and PR I did is okay. I tested it locally and I get nice output using expecations now πŸ™‚

plexus 2020-03-10T15:21:18.112600Z

cool! I'll have a good luck. Thank you for contributing to Kaocha!

dharrigan 2020-03-10T15:22:39.112800Z

you're welcome

dominicm 2020-03-10T15:24:49.113Z

I hope my questions aren't too burdensome. Fortunately my employer does allow contributions, so if something was major, I would be able to contribute. I'm hoping that my questions help improve kaocha more quickly under funding. It's a bit of a weak hope, so mostly I just hope I'm not too much trouble :). Open source & time is a hard thing, and I appreciate your time building cool things, and answering my questions.

defa 2020-03-10T17:42:14.113200Z

@plexus thanks! I really like Kaocha, good work! Will be using it daily from now on.