Tag Archives: nodejs

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

Website Development – Which Stack?

I’m wondering which way to go for a personal website development – I’ve always liked the idea of using the same language client and server side hence I’m voting for Nodejs which is JavaScript for the server (all clients are using HTML and JavaScript with most like angular on there as well)

Here’s the poll and feel free to enter your comments as well.