Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Last active August 29, 2015 14:08
Show Gist options
  • Save al-the-x/d245b6e1a5539db32710 to your computer and use it in GitHub Desktop.
Save al-the-x/d245b6e1a5539db32710 to your computer and use it in GitHub Desktop.
Starting point for Coding Dojos in JavaScript using Mocha and Chai
{
"scripts": {
"postinstall": "./node_modules/.bin/wiredep -s index.html"
}
}
node_modules
bower_components

Now with fewer Yaks to shave!

  • Download this gist (http://j.mp/bdconf-2014-dojo) and unzip into a new directory.
  • With NPM installed run npm install from the unpacked directory.
  • For browser testing, run bower install from the unpacked directory.
  • Use the task gulp web-tests to run web-code.js and web-tests.js in your browser.
  • Use the command npm test to run cli-code.js and cli-tests.js from the command line.
  • Get to coding!
{
"name": "just-enough-dojo",
"version": "1.0.0",
"authors": [
"David Rogers <hello@al-the-x.me>"
],
"main": "index.html",
"keywords": [
"tdd",
"mocha",
"chai"
],
"license": "GPL",
"homepage": "https://gist.github.com/al-the-x/d245b6e1a5539db32710",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components"
],
"dependencies": {
"mocha": "~2.0.1",
"chai": "~1.9.2"
}
}
var chai = require('chai'),
assert = chai.assert,
expect = chai.expect;
var mocha = require('mocha'),
suite = mocha.suite,
test = mocha.test,
setUp = mocha.setup,
tearDown = mocha.tearDown;
var code = require('./cli-code');
// chai.should() // Use with caution!
/* === Test Code === */
describe('example tests', function(){
it('should totally fail', function(){
assert.isFalse(true);
});
it('should similarly fail', function(){
expect(false).to.be.true;
});
});
suite('also valid', function(){
test('something', function(){
assert.isFalse(true);
});
});
var gulp = require('gulp'),
connect = require('gulp-connect'),
open = require('gulp-open'),
exec = require('child_process').exec;
/* === Web Testing === */
gulp.task('web-tests', [ 'web-open', 'web-watch' ]);
/* === CLI Testing === */
gulp.task('cli-tests', function(cb){
console.log('Please run `npm test` instead');
});
{ // Supplementary tasks...
gulp.task('web-serve', function(){
connect.server({
livereload: true,
});
});
gulp.task('web-open', [ 'web-serve' ], function(){
return gulp.src('./index.html')
.pipe(open('/', {
url: 'http://localhost:8080'
}));
});
gulp.task('web-reload', function(){
gulp.src([ 'web-*.js', 'index.html' ])
.pipe(connect.reload());
});
gulp.task('web-watch', function(){
gulp.watch([
'web-*.js', 'index.html'
], [ 'web-reload' ]);
})
} // END Supplementary tasks
<!doctype html>
<html>
<head>
<title>Mocha: web-tests.js</title>
<link rel="stylesheet" href="bower_components/mocha/mocha.css">
<!-- bower:css -->
<!-- endbower -->
</head>
<body>
<div id="mocha"></div>
<!-- bower:js -->
<!-- endbower -->
<script src="bower_components/mocha/mocha.js"></script>
<script src="bower_components/chai/chai.js"></script>
<script>
mocha.setup('bdd');
mocha.setup('tdd');
</script>
<script src="web-code.js"></script>
<script src="web-tests.js"></script>
<script>
mocha.checkLeaks();
mocha.globals([ 'LiveReload' ]);
mocha.run();
</script>
</body>
</html>
{
"name": "just-enough-dojo",
"version": "1.0.0",
"description": "* Download this gist and unzip into a new directory. * With [NPM](http://npmjs.org) installed run `npm install` from the unpacked directory. * For browser testing, run `bower install` from the unpacked directory. * Use the task `gulp serve` to run `web-code.js` and `web-test.js` in your browser. * Use the task `gulp test` to run `cli-code.js` and `cli-test.js` from the command line.",
"main": "index.js",
"scripts": {
"test": "mocha --watch cli-*.js"
},
"repository": {
"type": "git",
"url": "git@gist.github.com:/d245b6e1a5539db32710.git"
},
"keywords": [
"tdd",
"mocha",
"chai"
],
"author": "David Rogers <hello@al-the-x.me>",
"license": "GPL",
"dependencies": {
"bower": "^1.3.12",
"chai": "^1.9.2",
"chalk": "^0.5.1",
"gulp": "^3.8.9",
"gulp-connect": "^2.2.0",
"gulp-open": "^0.3.0",
"mocha": "^2.0.1",
"wiredep": "^2.0.0"
}
}
var assert = chai.assert;
describe('sample tests', function(){
it('should fail', function(){
assert.isTrue(false);
});
});
suite('also valid', function(){
test('something', function(){
assert.isFalse(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment