Using clojure.spec in ClojureScript SPA

I’m working on Pondent (repository), a posting utility written in ClojureScript and made available via GitHub Pages (app). After authorising with GitHub, a user can commit files to a repository they administer. The app is primarily intended to be used to add posts to a Jekyll- or Hugo-powered blog. It runs entirely in the browser with no backend.

This is my first significant project in ClojureScript and I built the initial prototype without tests. Now that it works in a rudimentary fashion I want to put in place something more robust. Rather than add unit tests, I decided to spec the functions in the app. Here is an example of the specs in the pondent.time namespace.

I have a few questions:

  1. Is eschewing unit tests in favour of specs a good approach for a ClojureScript application?

  2. From what I understand, I would need to create generators for specs that describe objects like goog.date.DateTime if I wanted to use property-based testing. That seems both potentially error-prone and like a lot of work. Would I be better off simply sticking to unit tests?

  3. It seems like adding the specs led to a decent increase in the size of the compiled JavaScript. Should I be looking to skip the specs for release builds? Is there a preferred way to go about doing this?

  4. Multiple namespaces use specs that describe similarly shaped data (e.g. a spec of a string representing a URL). At the moment, I define these specs in each namespace separately but that seems wasteful. Is there a preferred way to organise these kind of ‘shared’ specs?

If there are more general resources that people would recommend, please feel free to answer with those, too. Thanks in advance!

I discussed this on the #clojure channel on Freenode and, following the feedback, decided to move the specs out of the namespaces and into separate spec namespaces that are kept in test/ and only brought in during development and testing.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.