Compare commits
No commits in common. "master" and "v1.4.5" have entirely different histories.
7 changed files with 22 additions and 180 deletions
|
@ -111,11 +111,9 @@ $ eltro --watch my_watch_name --npm build
|
|||
|
||||
Not only does eltro allow you to use any assertion library of your own choosing, it also comes with it's own assertion library based on node's default [assert](https://nodejs.org/api/assert.html) with a few extra methods:
|
||||
|
||||
* `assert.equalWithMargin(value, test, margin, [message])`: Check if number value is equal to test with error margin.
|
||||
* `assert.notOk(value, [message])`: Assert value is not ok.
|
||||
* `assert.match(value, test, [message])`: Check if value matches RegExp test.
|
||||
* `assert.notMatch(value, [message])`: Check if value does not match RegExp test.
|
||||
* `assert.throwsAndCatch(fn, [message])`: Checks if function fn throws and returns the thrown error.
|
||||
* `assert.isFulfilled(promise, [message])`: Assert the promise resolves.
|
||||
* `assert.isRejected(promise, [message])`: Assert the promise gets rejects.
|
||||
|
||||
|
|
|
@ -57,14 +57,6 @@ assert.throwsAndCatch = (fn, message) => {
|
|||
return err
|
||||
}
|
||||
|
||||
assert.equalWithMargin = (value, test, margin = 0.005, message) => {
|
||||
assert.strictEqual(typeof value, 'number', 'Value should be number')
|
||||
assert.strictEqual(typeof test, 'number', 'Test should be number')
|
||||
|
||||
let difference = Math.abs(value - test)
|
||||
assert.ok(difference <= margin, message || `${value} ± ${margin} != ${test} (difference of ${difference} > ${margin})`)
|
||||
}
|
||||
|
||||
assert.isFulfilled = (promise, message) => {
|
||||
return Promise.resolve(true)
|
||||
.then(() => promise)
|
||||
|
|
|
@ -117,7 +117,6 @@ process.on('uncaughtException', function(err) {
|
|||
})
|
||||
|
||||
function Eltro() {
|
||||
this.process = process
|
||||
this.__timeout = 2000
|
||||
this.hasExclusive = false
|
||||
this.reporter = 'list'
|
||||
|
@ -160,8 +159,8 @@ Eltro.prototype.begin = function() {
|
|||
}
|
||||
|
||||
Eltro.prototype.__runTest = async function(stats, test, prefix = 'Test', child = null) {
|
||||
if (this.reporter === 'list' && prefix === 'Test') {
|
||||
this.process.stdout.write(' \x1b[90m? ' + test.name + '\x1b[0m')
|
||||
if (this.reporter === 'list') {
|
||||
process.stdout.write(' \x1b[90m? ' + test.name + '\x1b[0m')
|
||||
}
|
||||
|
||||
let markRealTest = child || test
|
||||
|
@ -280,24 +279,24 @@ Eltro.prototype.__runTest = async function(stats, test, prefix = 'Test', child =
|
|||
this.captureOutsideExceptions = null
|
||||
|
||||
if (this.reporter === 'list') {
|
||||
readline.clearLine(this.process.stdout, 0)
|
||||
readline.cursorTo(this.process.stdout, 0, null)
|
||||
readline.clearLine(process.stdout, 0)
|
||||
readline.cursorTo(process.stdout, 0, null)
|
||||
if (markRealTest.skipTest) {
|
||||
this.process.stdout.write(' \x1b[94m- ' + markRealTest.name + '\x1b[0m\n')
|
||||
process.stdout.write(' \x1b[94m- ' + markRealTest.name + '\x1b[0m\n')
|
||||
} else if (!markRealTest.error) {
|
||||
if (!test.name.startsWith('~')) {
|
||||
this.process.stdout.write(' \x1b[32m√\x1b[90m ' + markRealTest.name + ' (' + markRealTest.totalTime + 'ms)\x1b[0m\n')
|
||||
process.stdout.write(' \x1b[32m√\x1b[90m ' + markRealTest.name + ' (' + markRealTest.totalTime + 'ms)\x1b[0m\n')
|
||||
}
|
||||
} else if (prefix === 'Test') {
|
||||
this.process.stdout.write(' \x1b[31m' + this.failedTests.length + ') ' + markRealTest.name + ' (' + markRealTest.totalTime + 'ms)\x1b[0m\n')
|
||||
process.stdout.write(' \x1b[31m' + this.failedTests.length + ') ' + markRealTest.name + ' (' + markRealTest.totalTime + 'ms)\x1b[0m\n')
|
||||
}
|
||||
} else if (this.reporter === 'dot') {
|
||||
if (markRealTest.skipTest) {
|
||||
this.process.stdout.write('\x1b[94m.\x1b[0m')
|
||||
} else if (markRealTest.error) {
|
||||
this.process.stdout.write('\x1b[31m.\x1b[0m')
|
||||
process.stdout.write('\x1b[94m.\x1b[0m')
|
||||
} else if (!markRealTest.error) {
|
||||
process.stdout.write('\x1b[32m.\x1b[0m')
|
||||
} else if (prefix === 'Test') {
|
||||
this.process.stdout.write('\x1b[32m.\x1b[0m')
|
||||
process.stdout.write('\x1b[31m.\x1b[0m')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +304,7 @@ Eltro.prototype.__runTest = async function(stats, test, prefix = 'Test', child =
|
|||
Eltro.prototype.__runGroup = async function(g, stats) {
|
||||
if (g.tests.length) {
|
||||
if (this.reporter === 'list') {
|
||||
this.process.stdout.write(' ' + g.name + '\n')
|
||||
console.log(' ' + g.name)
|
||||
}
|
||||
}
|
||||
if (g.before) {
|
||||
|
@ -352,8 +351,8 @@ Eltro.prototype.__runGroup = async function(g, stats) {
|
|||
|
||||
Eltro.prototype.run = async function() {
|
||||
if (this.reporter && this.reporter !== 'test') {
|
||||
this.process.stdout.write('' + '\n')
|
||||
this.process.stdout.write('' + '\n')
|
||||
console.log('')
|
||||
console.log('')
|
||||
}
|
||||
|
||||
captureUnknownErrors(this)
|
||||
|
@ -382,23 +381,23 @@ Eltro.prototype.run = async function() {
|
|||
}
|
||||
}
|
||||
} else if (this.reporter) {
|
||||
this.process.stdout.write('' + '\n')
|
||||
this.process.stdout.write('' + '\n')
|
||||
console.log('')
|
||||
console.log('')
|
||||
if (stats.passed) {
|
||||
this.process.stdout.write(' \x1b[32m' + stats.passed + ' passing \x1b[90m(' + (end[0] * 1000 + Math.round(end[1] / 1000000)) + 'ms)\x1b[0m' + '\n')
|
||||
console.log(' \x1b[32m' + stats.passed + ' passing \x1b[90m(' + (end[0] * 1000 + Math.round(end[1] / 1000000)) + 'ms)\x1b[0m')
|
||||
}
|
||||
if (stats.failed) {
|
||||
this.process.stdout.write(' \x1b[31m' + stats.failed + ' failing\x1b[0m' + '\n')
|
||||
console.log(' \x1b[31m' + stats.failed + ' failing\x1b[0m')
|
||||
}
|
||||
if (stats.skipped) {
|
||||
this.process.stdout.write(' \x1b[94m' + stats.skipped + ' pending\x1b[0m' + '\n')
|
||||
console.log(' \x1b[94m' + stats.skipped + ' pending\x1b[0m')
|
||||
}
|
||||
this.process.stdout.write('' + '\n')
|
||||
console.log('')
|
||||
|
||||
if (this.failedTests.length) {
|
||||
for (let x = 0; x < this.failedTests.length; x++) {
|
||||
let test = this.failedTests[x];
|
||||
this.process.stdout.write(' ' + (x + 1) + ') ' + test.name + ':' + '\n')
|
||||
console.log(' ' + (x + 1) + ') ' + test.name + ':')
|
||||
printError(test.error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ export function stub(returnFunc = null) {
|
|||
func.lastCall = null
|
||||
func.called = false
|
||||
func.callCount = 0
|
||||
func.calls = calls
|
||||
|
||||
func.findCall = function(fn) {
|
||||
for (let call of calls) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eltro",
|
||||
"version": "1.5.0",
|
||||
"version": "1.4.5",
|
||||
"description": "Eltro is a tiny no-dependancy test framework for node",
|
||||
"main": "index.mjs",
|
||||
"scripts": {
|
||||
|
|
|
@ -29,41 +29,6 @@ t.describe('#notOk()', function() {
|
|||
})
|
||||
})
|
||||
|
||||
t.describe('#equalWithMargin()', function() {
|
||||
t.test('should support default margin for floating point math', function() {
|
||||
let check = 0.1 + 0.2
|
||||
|
||||
assertExtended.throws(function() {
|
||||
assertExtended.strictEqual(check, 0.3)
|
||||
}, assertExtended.AssertionError)
|
||||
|
||||
assertExtended.equalWithMargin(check, 0.3)
|
||||
})
|
||||
|
||||
t.test('should support custom margin', function() {
|
||||
assertExtended.equalWithMargin(1, 2, 1)
|
||||
})
|
||||
|
||||
t.test('should fail if margin is too small', function() {
|
||||
assertExtended.throws(function() {
|
||||
assertExtended.equalWithMargin(1, 2, 0.9)
|
||||
}, assertExtended.AssertionError)
|
||||
})
|
||||
|
||||
t.test('should support custom message', function () {
|
||||
const assertMessage = 'Hello world'
|
||||
let error = null
|
||||
|
||||
try {
|
||||
assertExtended.equalWithMargin(1, 2, 0, assertMessage)
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
assert.ok(error)
|
||||
assert.match(error.message, new RegExp(assertMessage))
|
||||
})
|
||||
})
|
||||
|
||||
t.describe('#throwAndCatch()', function() {
|
||||
t.test('should work and return the original error', function() {
|
||||
const assertError = new Error('Speed')
|
||||
|
|
|
@ -8,9 +8,6 @@ function CreateT() {
|
|||
t.logger = {
|
||||
log: stub()
|
||||
}
|
||||
t.process = {
|
||||
stdout: { write: stub() }
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -287,60 +284,6 @@ e.describe('#beforeEach()', function() {
|
|||
assert.match(t.logger.log.getCallN(4)[0], /DDDD/)
|
||||
assert.match(t.logger.log.getCallN(4)[0], /BBBB/)
|
||||
})
|
||||
|
||||
e.describe('reporter', function() {
|
||||
e.test('should not log before each with reporter list', async function() {
|
||||
const t = CreateT()
|
||||
t.reporter = 'list'
|
||||
t.begin()
|
||||
t.describe('BBBB', function() {
|
||||
t.beforeEach(function() {})
|
||||
|
||||
t.describe('CCCC', function() {
|
||||
t.test('c1', function() { })
|
||||
t.test('c2', function() { })
|
||||
})
|
||||
|
||||
t.describe('DDDD', function() {
|
||||
t.test('d1', function() { })
|
||||
})
|
||||
|
||||
t.test('AAAA', function() { })
|
||||
})
|
||||
await t.run()
|
||||
for (let row of t.process.stdout.write.calls) {
|
||||
assert.notMatch(row.filter(x => x).join(' '), /before each/i)
|
||||
}
|
||||
})
|
||||
|
||||
e.test('should not log success before each with reporter dot', async function() {
|
||||
const t = CreateT()
|
||||
t.reporter = 'dot'
|
||||
t.begin()
|
||||
t.describe('BBBB', function() {
|
||||
t.beforeEach(function() {})
|
||||
|
||||
t.describe('CCCC', function() {
|
||||
t.test('c1', function() { })
|
||||
t.test('c2', function() { })
|
||||
})
|
||||
|
||||
t.describe('DDDD', function() {
|
||||
t.test('d1', function() { })
|
||||
})
|
||||
|
||||
t.test('AAAA', function() { })
|
||||
})
|
||||
await t.run()
|
||||
let total = 0
|
||||
for (let row of t.process.stdout.write.calls) {
|
||||
if (row.filter(x => x).join(' ').match(/\[32m\./)) {
|
||||
total++
|
||||
}
|
||||
}
|
||||
assert.strictEqual(total, 4)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
e.describe('#after()', function() {
|
||||
|
@ -736,60 +679,6 @@ e.describe('#afterEach()', function() {
|
|||
assert.match(t.logger.log.getCallN(5)[0], /JJJJ/)
|
||||
assert.match(t.logger.log.getCallN(5)[0], /YYYY/)
|
||||
})
|
||||
|
||||
e.describe('reporter', function() {
|
||||
e.test('should not log before each with reporter list', async function() {
|
||||
const t = CreateT()
|
||||
t.reporter = 'list'
|
||||
t.begin()
|
||||
t.describe('BBBB', function() {
|
||||
t.afterEach(function() {})
|
||||
|
||||
t.describe('CCCC', function() {
|
||||
t.test('c1', function() { })
|
||||
t.test('c2', function() { })
|
||||
})
|
||||
|
||||
t.describe('DDDD', function() {
|
||||
t.test('d1', function() { })
|
||||
})
|
||||
|
||||
t.test('AAAA', function() { })
|
||||
})
|
||||
await t.run()
|
||||
for (let row of t.process.stdout.write.calls) {
|
||||
assert.notMatch(row.filter(x => x).join(' '), /after each/i)
|
||||
}
|
||||
})
|
||||
|
||||
e.test('should not log success before each with reporter dot', async function() {
|
||||
const t = CreateT()
|
||||
t.reporter = 'dot'
|
||||
t.begin()
|
||||
t.describe('BBBB', function() {
|
||||
t.afterEach(function() {})
|
||||
|
||||
t.describe('CCCC', function() {
|
||||
t.test('c1', function() { })
|
||||
t.test('c2', function() { })
|
||||
})
|
||||
|
||||
t.describe('DDDD', function() {
|
||||
t.test('d1', function() { })
|
||||
})
|
||||
|
||||
t.test('AAAA', function() { })
|
||||
})
|
||||
await t.run()
|
||||
let total = 0
|
||||
for (let row of t.process.stdout.write.calls) {
|
||||
if (row.filter(x => x).join(' ').match(/\[32m\./)) {
|
||||
total++
|
||||
}
|
||||
}
|
||||
assert.strictEqual(total, 4)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
let commonBeforeTests = ['before', 'beforeEach']
|
||||
|
|
Loading…
Reference in a new issue