Browserify test suite

Our tests run in the browser and on node! Switching to browserify made this necessary.
This commit is contained in:
Kieran Sedgwick 2014-05-26 16:29:46 -04:00
parent 2d245a0b26
commit a4c0874668
3 changed files with 35 additions and 22 deletions

View File

@ -57,7 +57,10 @@ module.exports = function(grunt) {
dest: "./dist/filer.js",
options: {
standalone: 'Filer',
builtins: false
browserifyOptions: {
builtins: false,
commondir: false
}
}
},
testVersion: {
@ -65,14 +68,24 @@ module.exports = function(grunt) {
dest: "./dist/filer-test.js",
options: {
standalone: 'Filer',
builtins: false
browserifyOptions: {
builtins: false,
commondir: false
}
}
},
testApp: {
src: "./tests/index.js",
dest: "./tests/test-bundle.js",
options: {
standalone: 'Filer test suite'
}
}
},
shell: {
mocha: {
command: './node_modules/.bin/mocha --reporter list --no-exit tests/node-runner.js'
command: './node_modules/.bin/mocha --reporter list --no-exit tests/index.js'
}
},
@ -177,7 +190,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('develop', ['clean', 'browserify:standalone']);
grunt.registerTask('filer-test', ['clean', 'browserify:testVersion']);
grunt.registerTask('filer-test', ['clean', 'browserify:testVersion', 'browserify:testApp']);
grunt.registerTask('release', ['develop', 'uglify']);
grunt.registerTask('check', ['jshint']);
@ -210,7 +223,7 @@ module.exports = function(grunt) {
'npm-publish'
]);
});
grunt.registerTask('test-node', ['check', 'filer-test', 'connect:server_for_node', 'shell:mocha']);
grunt.registerTask('test-node', ['check', 'clean', 'connect:server_for_node', 'shell:mocha']);
grunt.registerTask('test-browser', ['check', 'filer-test', 'connect:server_for_browser']);
grunt.registerTask('test', ['test-node']);

View File

@ -6,26 +6,18 @@
<script src="../bower_components/chai/chai.js"></script>
<script src="../bower_components/mocha/mocha.js"></script>
<script>
// Polyfill for function.bind, which PhantomJS seems to need, see
// https://gist.github.com/Daniel-Hug/5682738/raw/147ec7d72123fbef4d7471dcc88c2bc3d52de8d9/function-bind.js
Function.prototype.bind = (function () {}).bind || function (b) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
mocha.setup('bdd').timeout(5000).slow(250);;
function c() {}
var a = [].slice,
f = a.call(arguments, 1),
e = this,
d = function () {
return e.apply(this instanceof c ? this : b || window, f.concat(a.call(arguments)));
};
c.prototype = this.prototype;
d.prototype = new c();
return d;
// Intentional globals
expect = chai.expect;
assert = chai.assert;
window.onload = function() {
mocha.checkLeaks();
mocha.run();
};
</script>
<script src="../lib/require.js" data-main="require-config"></script>
<script src="test-bundle.js"></script>
</head>
<body>
<div id="mocha"></div>

8
tests/index.js Normal file
View File

@ -0,0 +1,8 @@
// Tests to be run are defined in test-manifest.js
// For Nodejs context, expose chai's expect method
if (typeof GLOBAL !== "undefined") {
GLOBAL.expect = require('chai').expect;
}
require('./test-manifest.js');