tunnckoCore / blankr

:heart: tasks, todos, ideas, streaks, WIP, etc
https://i.am.charlike.online
4 stars 1 forks source link

(WIP) Mukla - promise-based test framework #26

Closed tunnckoCore closed 9 years ago

tunnckoCore commented 9 years ago

Very raw... Async and unordered by nature.. but very easy, small and awesome!

var assert = require('assert');
var mukla = require('mukla'); // mukla v1
var log = require('log-symbols');
var tests = [];

function mukla(title, _then) {
  tests.push(title);
  var promise = Promise.resolve('');
  return promise.then(_then.bind(this)).then(function() {
    console.log(log.success, title);
  }).catch(function(err) {
    console.log(log.error, title);
    console.log('message: %s', err.message);
    console.log('    ---');
    console.log('    actual: %s', err.actual);
    console.log('    expected: %s', err.expected);
    console.log('    operator: %s', err.operator);
    console.log('    ---');
  })
}

mukla('should 1+1 be 2', function() {
  assert.strictEqual(1+1, 2);
})
mukla('should typeof _cb be function', function() {
  var _cb = 'string 123456'
  assert.strictEqual(typeof _cb, 'function');
})
mukla('should 1+1+1*2 be 4', function() {
  assert.strictEqual(1+1+1*2, 4);
})

But this have bugs.. like not work if asserts are in callbacks.. So the solution will be (i think) to port assert methods to mukla specific methods like this below, also this will free the way for nesting and sub titles

mukla('should be strictly equal').equal(1+2, 3);

more complex

mukla('should work with both callback and promise api', function() {
  return hybridGot('http://todomvc.com', function(err, res) {
    mukla('should `err` be `null`').equal(err, false);
    mukla('should `res[0]` starts with `<`').equal(res[0][0], '<');
    mukla('should `res[1]` be truthy value').truthy(res[1]);
  })
  .then(function(res) {
    mukla('should `res[0]` starts with `<`').equal(res[0][0], '<');
    mukla('should `res[1]` be truthy value').truthy(res[1]);
  });
});
tunnckoCore commented 9 years ago

done. https://github.com/tunnckoCore/mukla