A Cloud9 Custom Runner combining TypeScript and Mocha

The online IDE Cloud 9 is just awesome.  It is amongst a number of online IDEs out there, of which I think it is the best.  With Microsoft also making .NET opensource and available on all platforms I can also see myself doing .NET development on this as well.  Yes I know there is Monaco from Microsoft but that is still immature and yes there is Mono on linux as well but that requires fiddling about.

At the moment I’m doing node.js development with expressjs and now with typescript in the mix as well.  Typescript looks awesome as well.  I’ve ported some javascript code over to Typescript and it feels really nice.

However, Cloud9 does not have a runner setup for typescript compilation so I decided to set one up myself.  Cloud 9 provides a way to do this by adding a New Runner from the Run Menu.  I created the following script that associates the .ts file extension with the tsc compiler.  It will also then run the associated mocha test which existed when the code was just pure javascript.  It does rely on a naming convention and directory location for the test, so as long as you stick to a convention you will be Ok.  Here is the script:

{
“cmd” : [“bash”, “–login”, “-c”, “rm $file_base_name’.js’;tsc –sourcemap –module commonjs $file; mocha test/$file_base_name’Tests.js'”],
“info” : “Compiling Typescript file $file”,
“env” : {},
“selector” : “source.ts”
}

It uses bash to run multiple commands, one for the Tyepscript compiler and then followed by the mocha test runner.  Prior to running these command it deletes the previous .js file and if tsc fails the old file is still there and the test runner will pick that up still and we rather not have that.

I found when I converted the javascript implementation of the main file to typescript and compiled, my tests just worked.  The tests are still in pure javascript.  I’m still entertaining the idea of using Steve Fenton’s tsUnit but I fear it may not be as mature as the javascript test ecosystem.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: