Getting a handle to __filename/current script?

I’ve made run-in-mocha to try to find a way of running Mocha in RunKit. It depends on __filename for this to work, which I knew beforehand would be a bit sketcy to rely on, as you probably filter out stuff like this for security reasons.

Is there a way of getting a reference to the current script, as __filename doesn’t work?

You can see the internals here.

Hey there,

__filename points to the RunKit “runtime” (all the code that makes multiple cells work, write outputs, etc) which lives at app/index.js.

I imagine what you want is your notebook code? Because of the REPL nature of our notebooks, your notebook code does not live on disk, it’s fed into our runtime cell by cell.

In RunKit you have full access to the filesystem, so the best thing to do is write your code to disk, and run it that way:

- Randy

1 Like

Thank you for replying! It’s great to know how that works, yet it’s somewhat unfulfilling to see the actual solution, as it doesn’t make for the greatest user-experience to write a test suite inside of a string. When I made mini-mocha it had the right UX, as it made it possible to copy-paste existing mocha test suites and make them run without changes in RunKit (at least the 90% most used subset of Mocha).

Unfortunately, mini-mocha re-implements a lot of the machinery, which is a bit of a drag, considering it’s possible to start Mocha from inside of Node (as run-in-mocha does), so I thought I’d give it a go. Oh, well. I guess I can’t have my cake and eat it too :smile: