- 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 runweb-code.js
andweb-tests.js
in your browser. - Use the command
npm test
to runcli-code.js
andcli-tests.js
from the command line. - Get to coding!
Last active
August 29, 2015 14:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"postinstall": "./node_modules/.bin/wiredep -s index.html" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
bower_components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "just-enough-dojo", | |
"version": "1.0.0", | |
"authors": [ | |
"David Rogers <[email protected]>" | |
], | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": "[email protected]:/d245b6e1a5539db32710.git" | |
}, | |
"keywords": [ | |
"tdd", | |
"mocha", | |
"chai" | |
], | |
"author": "David Rogers <[email protected]>", | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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