Fork me on GitHub
#shadow-cljs
<
2023-08-13
>
itaied15:08:24

Does anybody here have experience with running cljs code in jest runner? I want to import code from my cljs app to run in my js testing project. I have compiled the cljs module with

:routes {:target :node-library
                   :output-to "ui-tests/lib.js"
                   :exports {:hello test.routes/hello}}
I can execute it using node
node
Welcome to Node.js v16.15.0.
Type ".help" for more information.
> var x = require("./lib")
undefined
> x
{ hello: [Getter] }
> x.hello
'hello from cljs'
> 
But importing the code from my test.js (running using jest) i get the following error:
● Test suite failed to run

    ReferenceError: goog is not defined

      at .shadow-cljs/builds/routes/dev/out/cljs-runtime/goog/debug/error.js:1:1
      at call (ui-tests/lib.js:70:44)
      at SHADOW_IMPORT (ui-tests/lib.js:1357:1)
      at factory (ui-tests/lib.js:5:26)
      at Object.<anonymous> (ui-tests/lib.js:9:2)
      at Object.require (ui-tests/layout.test.js:7:11)
Jest is configured using puppeteer
module.exports = {
  preset: "jest-puppeteer",
  testRegex: "/ui-tests/.*test\\.js$",
};

thheller16:08:33

for integration into other tools such as jest you might want to use :target :npm-module instead

thheller16:08:20

I don't know how jest loads code but it might be doing too much processing

itaied17:08:05

thanks! it worked!