Skip to content

Instantly share code, notes, and snippets.

Last active March 21, 2017 04:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
[RC Diary] You never forget your first alive mutant (-91)

[RC Diary] You never forget your first alive mutant (-91)

Project lamp

We are going to add another feature: the chance to evaluate arbitrary code and see its result in a dedicated area.

This will be achieved by taking what the user is looking at, typically a small function, preprending to it some imports and then appending a main where user input is appended to look like


and then reassigning JavaScript's console.log to a function that would look something like

window.console.log = function(result) {
  return function(selector) {

So that we have some sort of REPL.


So the error I was doing shows how little I understand about ClojureScript, I was passing around a ClojureScript map {} while instead I needed a JavaScript object #js {} or (js-obj).

I needed this in the following code:

(defn create-mocha-context
  "creates a context in which all required functions and
  variables are defined, so mocha can run fine.
  it does this by passing a mocha-context as payload to
  pre-required event, mocha-context is then enriched with
  all required functions, like it before after describe etc"
  (def Mocha (node/require "mocha"))
  (let [mocha-context #js {} ;; ** THIS IS THE IMPORTANT LINE **
        mocha (Mocha. {:reporter "reporter"})]
    (.emit (.-suite mocha) "pre-require" mocha-context nil mocha)
    (.createContext vm mocha-context)))

In the "important line" I was passing {} instead, which is immutable because it's a ClojureScript data structure so I was getting back {} from the function invocation, instead of the whole thing.

In the end I managed to mutate the contents of a file in memory, now I just need to cleanup the project ready for the presentation on Thursday, which means:

  • write a series of steps runnable from src/cerebro/core.cljs
  • polish the introduction to mutation testing addressing the code coverage fail scenario

One of the things I would love to do in the very next future is introduce deftype where needed in the codebase, so my data handling can be easier, I still have to see how does that translates in JavaScript though.


  • Cerebro
  • project lamp
  • still need some attention needed for timsort, radix sort, dijkstra algo
  • chapter 3 of the little schemer in Clojure
  • allow some time to think
  • find a new apartment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment