Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:35:06+00:00 2026-06-17T15:35:06+00:00

I want to be able to inject javascript code into my app while testing.

  • 0

I want to be able to inject javascript code into my app while testing. Following this line of reasoning, I do the following in a repl.

=> (cljs.closure/build '(swap! my-project.my-namespace.my-atom inc) {})
<= "goog.addDependency(\"base.js\", ['goog'], []);\ngoog.addDependency(\"../x8LL7.js\", [], []);"

I then

=> more out/x8LL7.js 
<= cljs.core.swap_BANG_.call(null,my_project.my_namespace.my_atom,cljs.core.inc);

Yes, it appears that this is what I want. I could be mistaken, but I do not think I need the “base.js” dependency, as it is already included in the running app under test (which is using :simple :optimizations).

My question is, how can I get the content of file out/x8LL7.js? I just want the string that is written to out/x8LL7.js as I have no use for the deps file string that is returned from cljs.closure/build.

If it isn’t easy, then I guess I can just parse the returned deps string, open the file myself and then use the content; not a big deal. Still, I was hoping there was a more direct way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:35:07+00:00Added an answer on June 17, 2026 at 3:35 pm

    Mostly just a note to myself, but in case someone needs to know, here is how I quick fixed it.

    (def cljs-to-js-dir "_cljs_to_js_out")
    
    (def js-options { :output-dir cljs-to-js-dir})
    
    (defn js-compile [quoted-expr]
      (let [ result (cljs.closure/build quoted-expr js-options)
             file-name  ((re-find #"(/.+\.js)" result) 0)]
        (slurp (str  cljs-to-js-dir "/" file-name))))
    
    (defmacro to-js [expr]
      (js-compile `((fn [] ~expr))))
    

    Using this code, you can then (from the repl) type:

    => (to-js (swap! my-project.my-namespace.my-atom inc))
    <= "(function (){\nreturn cljs.core.swap_BANG_.call(null,my_project.my_namespace.my_atom,cljs.core.inc);\n}).call(null);\n"
    

    I bet you are curious as to why I wrapped the expr(ession) in a immediately called no argument function. It is because cljs.closure/build will optimize away code if it is not actually used. For instance:

    => (js-compile '(fn [a b] (+ a b))) 
    <= ""
    

    however

    => (js-compile '((fn [a b] (+ a b)) 2 3))
    <= "(function (a,b){\nreturn (a + b);\n}).call(null,2,3);\n"
    

    Details aside, (to-js) seems to do what I want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to inject ViewModels into the Views in my Windows
I want to be able to inject model state into a service. Service public
I want to be able to inject a .dll into a running JVM process.
I want to be able to do the following actions with a form submit
I have a DLL that I inject into another process but I want to
I want to use @AutoWired to inject a non-managed bean configured with @Component into
I want to do something like this: var w = window.open(javascript: makeAnAjaxRequest();); My question
I'm using an MVC setup and I'm trying to inject javascript into my views
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.