Skip to content

Project setup for writing and testing server side modules using ES7 and CoffeeScript using Gulp 4, Mocha and Chai

Notifications You must be signed in to change notification settings

open-medicine-initiative/teatime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coffee table

Coffee table is a setup of various JavaScript technologies, ready to be used as a basis for implementing server side JavaScript modules. This template integrates Babel and CoffeeScript transpilers such that modules can be written and tested in either of both languages.

The build system is Gulp 4 and build files are written in CoffeeScript ( UNBIASED sidenote: because this is what build files should look like :)

Mocha is used as test runner and Chai is the preferred tool for specifying assertions. It is exposed in global context so that tests don't need to require(...)

Gulp watchers are used to provide automatic re-execution of tests whenever a file (spec or module) changed. Using Gulp 4 it is even quite simple to only re-transpile the source files that have actually changed. This incremental re-transpilation is very handy because having babel and coffee in the stack does incurr quite some overhead.

To install and run (zero) tests:

$ npm install gulpjs/gulp-cli#4.0 -g
$ npm install
$ npm test

This will download and install all required dependencies and make gulp run the tests. Since there are no files under src it will just give a green light indicating that everything was fine and none of the zero tests failed.

Tutorial

Let's assume we have the folling (dumb) module written in ES7 style JavaScript The module is src/invert.js:

'use strict';

export function invert(bool) {
	console.log (`${bool} inverted is ${!bool}`);
	return !bool;
}

Of course we also write a test and place it right next to the model (YES, that is good style...) The test file is src/invert.spec.coffee:

invert = require('./invert').invert

describe 'inversion of booleans', ->
	it 'should return the inverted values', ->
		expect( invert false ).to .equal true

Running tests will now pick up the spec.coffee, transpile it and feed it to mocha for execution

$ npm test

Againg, green lights. This time with an actual test run.

About

Project setup for writing and testing server side modules using ES7 and CoffeeScript using Gulp 4, Mocha and Chai

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published