Permalink
Browse files

initial mocha testing shim harness

  • Loading branch information...
0 parents commit b51aab40988ce4a4f13cb57d9afa7a4d1993cc6a @substack committed Jan 20, 2012
Showing with 3,322 additions and 0 deletions.
  1. +34 −0 array.js
  2. +56 −0 harness.js
  3. +3,226 −0 mocha.js
  4. +6 −0 test.sh
@@ -0,0 +1,34 @@
+describe('Array', function(){
+ describe('#indexOf()', function(){
+ it('should return -1 when the value is not present', function(){
+ var arr = [1,2,3];
+ assert(-1 == arr.indexOf(5));
+ })
+
+ it('should be pending')
+
+ it('should return the correct index when the value is present', function(){
+ var arr = [1,2,3];
+ assert(0 == arr.indexOf(1)); // just to test indentation
+ assert(1 == arr.indexOf(2));
+ })
+ })
+})
+
+describe('Array', function(){
+ describe('#pop()', function(){
+ it('should remove and return the last value', function(done){
+ var arr = [1,2,3];
+ assert(arr.pop() == 3);
+ setTimeout(function(){
+ doesNotExist();
+ }, 0);
+ })
+
+ it('should adjust .length', function(){
+ var arr = [1,2,3];
+ arr.pop();
+ assert(arr.length == 2);
+ })
+ })
+})
@@ -0,0 +1,56 @@
+function assert(expr, msg) {
+ if (!expr) throw new Error(msg || 'failed');
+}
+
+var suite = new mocha.Suite;
+var utils = mocha.utils;
+var Reporter = function (runner) {
+ var push = require('/push');
+
+ mocha.reporters.Base.call(this, runner);
+
+ runner.on('fail', function (test, err) {
+ push('assert', {
+ type : 'fail',
+ ok : false,
+ name : test.fullTitle(),
+ found : err.toString(),
+ wanted : undefined
+ });
+ if (err.uncaught) runner.emit('test end', test);
+ });
+
+ runner.on('pass', function (test) {
+ push('assert', {
+ type : 'ok',
+ ok : true,
+ name : test.fullTitle(),
+ found : undefined,
+ wanted : undefined
+ });
+ });
+
+ runner.on('test end', function (test) {
+ push('testEnd', {});
+ });
+
+ runner.on('suite', function (suite) {
+ push('testBegin', { name : test.fullName() });
+ });
+
+ runner.on('suite end', function (suite) {
+ push('end', {});
+ });
+
+ push('end', {});
+};
+
+mocha.interfaces.bdd(suite);
+suite.emit('pre-require', window);
+
+process.nextTick(function () {
+ suite.emit('run');
+ var runner = new mocha.Runner(suite);
+ var reporter = new Reporter(runner);
+ runner.run();
+});
Oops, something went wrong.

0 comments on commit b51aab4

Please sign in to comment.