Clojurians
#cljs-dev
<
2017-10-29
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

olivergeorge02:10:44

Hello. I can't seem to make stest/instrument's :stub option work. Is that a known limitation by any chance? Can't see any related JIRA tickets.

olivergeorge02:10:32

I've tried a simple test case and also the example given in the spec guide under 'Combining check and instrument'. Seems like the :stub fn is ignored.

olivergeorge03:10:26

This should reproduce what I see (all three invocations return same number but we expect the second number to be a random int)

(defn add2 [a b] 1.1)
(s/fdef add2 :args (s/cat :a int? :b int?) :ret int?)
(println ::a (add2 1 2))
(stest/instrument `add2 {:stub #{`add2}})
(println ::b (add2 1 2))
(stest/unstrument `add2)
(println ::c (add2 1 2))

olivergeorge03:10:30

Code works as expected from clojure repl.

abp11:10:20

If anybody has ideas on how to conditionally require the crypto API on node please comment! I've looked into it a bit and a try require crypto catch approach would work, but could unintentionally include the module when in a build environment targeting the browser and incorporating commonjs or can't that happen?

abp11:10:04

Also, for the latter case, we maybe could do some additional checks on window being bound and window being bound to the same object in a closure, but that's not ideal either..

dnolen13:10:54

@olivergeorge what is :stub supposed to do. Could probably be made to work, but I’m pretty sure it isn’t currently supported

dnolen13:10:13

@abp heya, I will look at it when I have time, it’s a pretty low priority ticket

abp13:10:00

oh sry, I meant to say I added a new patch again, which could be more efficient than the last one. Now the question is how I can Benchmark the different implementations (maybe on multiple browsers), if needed. Also I could do a proposal on conditional node require if you think it's worth a try. Also no problem, take your time, no one else even has looked into the new patches to catch mistakes, I think.

olivergeorge19:10:06

@dnolen stub should replace the function with a generator (using the :ret spec to generate results).

olivergeorge19:10:39

My use case was isolating a function so side effecting calls were stubbed before running stest/check

olivergeorge20:10:22

There's a section in the Spec Guide covering called "Combining check and instrument" which describes it along with a worked example.

olivergeorge20:10:50

Would you like me to raise a JIRA issue?

olivergeorge22:10:20

Pretty sure the problem is (some #{sym} stub) not matching inside cljs.spec.test.alpha/instrument-choose-fn. How symbols are managed isn't immediately clear but that's my guess at the cause. The stub arg looks like I expect (e.g. #{cljs.spec.test-test/add2}) but the sym arg looks like #object[B0] via nashorn. So no surprise the if statement doesn't do what we expect.

olivergeorge22:10:06

I'll log a ticket and add a patch including a test which fails.

olivergeorge22:10:20

I think the :replace feature has a problem stemming from the same underlying problem. I think resolving stubbing will fix replacing.