Skip to content

Commit

Permalink
Implement matcha b00tc4mp#391
Browse files Browse the repository at this point in the history
  • Loading branch information
PereHDZ committed Mar 1, 2024
1 parent db86056 commit 254c5bf
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
18 changes: 18 additions & 0 deletions staff/pere-hernandez/prototype/matcha/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function assert(value, target){
console.assert(value === target, value + ' equals ' + target)
}

function error(error, type, message){
console.assert(error.name === type, 'name')
console.assert(error.message === message, 'message')
}

function instanceOf(value, type) {
console.assert(value instanceof type === true, value + ' is instance of ' + type)
}

module.exports = {
assert: assert,
error: error,
instanceOf: instanceOf
}
50 changes: 50 additions & 0 deletions staff/pere-hernandez/prototype/matcha/matcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
console.log('MATCHA 🍵')

var matcha = {}
var logs = []

function describe(title, callback){
logs[logs.length] = title
console.log(title)

callback()
}

function it(title, callback) {
var log = '* ' + title

logs[logs.length] = log
console.log(log)

callback()
}

function expect(value) {
return {
toBe: function (expected) {
var matches = value === expected

if (!matches) {
var log = '❌ ' + value + ' to be ' + expected.name

logs[logs.length] = log
console.log(log)

return false
}
log = '✅ ' + value + ' to be ' + expected.name

logs[logs.length] = log
console.info(log)

return true
}
}
}

matcha.logs = logs
matcha.describe = describe
matcha.it = it
matcha.expect = expect

module.exports = matcha
58 changes: 58 additions & 0 deletions staff/pere-hernandez/prototype/matcha/matcha.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var assert = require('./assert')
var matcha = require('./matcha')

console.log('matcha')



console.log('> describe')

matcha.logs.length = 0
var run = false

assert.assert(!!matcha.describe, true)

matcha.describe('describe title', function() {
run = true
})

assert.assert(run, true)
assert.assert(matcha.logs[0], 'describe title')



console.log('> it')

matcha.logs.length = 0
run = false

assert.assert(!!matcha.it, true)

matcha.it('it title', function () {
run = true
})

assert.assert(run, true)
assert.assert(matcha.logs[0], '* it title')



console.log('> expect toBe (happy path)')

assert.assert(!!matcha.expect, true)

matcha.logs.length = 0
var result = matcha.expect(10).toBe(10)

assert.assert(result, true)
assert.assert(matcha.logs[0], '✅ 10 to be 10')



console.log('< expect toBe (unhappy path)')

matcha.logs.length = 0
result = matcha.expect(10).toBe(12)

assert.assert(result, false)
assert.assert(matcha.logs[0], '❌ 10 to be 12')

0 comments on commit 254c5bf

Please sign in to comment.