Browserify test suite
Our tests run in the browser and on node! Switching to browserify made this necessary.
This commit is contained in:
parent
2d245a0b26
commit
a4c0874668
23
gruntfile.js
23
gruntfile.js
|
@ -57,7 +57,10 @@ module.exports = function(grunt) {
|
||||||
dest: "./dist/filer.js",
|
dest: "./dist/filer.js",
|
||||||
options: {
|
options: {
|
||||||
standalone: 'Filer',
|
standalone: 'Filer',
|
||||||
builtins: false
|
browserifyOptions: {
|
||||||
|
builtins: false,
|
||||||
|
commondir: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
testVersion: {
|
testVersion: {
|
||||||
|
@ -65,14 +68,24 @@ module.exports = function(grunt) {
|
||||||
dest: "./dist/filer-test.js",
|
dest: "./dist/filer-test.js",
|
||||||
options: {
|
options: {
|
||||||
standalone: 'Filer',
|
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: {
|
shell: {
|
||||||
mocha: {
|
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.loadNpmTasks('grunt-browserify');
|
||||||
|
|
||||||
grunt.registerTask('develop', ['clean', 'browserify:standalone']);
|
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('release', ['develop', 'uglify']);
|
||||||
grunt.registerTask('check', ['jshint']);
|
grunt.registerTask('check', ['jshint']);
|
||||||
|
|
||||||
|
@ -210,7 +223,7 @@ module.exports = function(grunt) {
|
||||||
'npm-publish'
|
'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-browser', ['check', 'filer-test', 'connect:server_for_browser']);
|
||||||
grunt.registerTask('test', ['test-node']);
|
grunt.registerTask('test', ['test-node']);
|
||||||
|
|
||||||
|
|
|
@ -6,26 +6,18 @@
|
||||||
<script src="../bower_components/chai/chai.js"></script>
|
<script src="../bower_components/chai/chai.js"></script>
|
||||||
<script src="../bower_components/mocha/mocha.js"></script>
|
<script src="../bower_components/mocha/mocha.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// Polyfill for function.bind, which PhantomJS seems to need, see
|
mocha.setup('bdd').timeout(5000).slow(250);;
|
||||||
// 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
function c() {}
|
// Intentional globals
|
||||||
var a = [].slice,
|
expect = chai.expect;
|
||||||
f = a.call(arguments, 1),
|
assert = chai.assert;
|
||||||
e = this,
|
|
||||||
d = function () {
|
window.onload = function() {
|
||||||
return e.apply(this instanceof c ? this : b || window, f.concat(a.call(arguments)));
|
mocha.checkLeaks();
|
||||||
};
|
mocha.run();
|
||||||
c.prototype = this.prototype;
|
|
||||||
d.prototype = new c();
|
|
||||||
return d;
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="../lib/require.js" data-main="require-config"></script>
|
<script src="test-bundle.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="mocha"></div>
|
<div id="mocha"></div>
|
||||||
|
|
|
@ -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');
|
Loading…
Reference in New Issue