3

I am writing some cljs.test tests for a clojurescript library and have some JSON test data I would like to load in.

I'm unsure what function I can use to load the data from files local to the project.

I'm using lein-doo as the test runner, initially with a nodejs configuration, ideally I would like to load files in an agnostic manner if possible, but I'd be fine with a nodejs-specific answer.

Alex Brown
  • 51
  • 5

1 Answers1

2

Following Piotrek's link I have come up with the following nodejs-only function that accomplishes this:

(defn node-slurp [path]
    (let [fs (nodejs/require "fs")]
        (.readFileSync fs path "utf8")))

(Node documentation: File System - readFileSync)

Alex Brown
  • 51
  • 5