Rename from casette to eltro

This commit is contained in:
Jonatan Nilsson 2020-04-01 15:35:33 +00:00
parent ede442b930
commit 4d695338e0
8 changed files with 92 additions and 101 deletions

16
cli.mjs
View file

@ -3,10 +3,10 @@
// Get arguments
const [,, ...args] = process.argv
import c from './lib/casette.mjs'
import e from './lib/eltro.mjs'
import { CLI, printError } from './lib/cli.mjs'
c.begin()
e.begin()
const cli = new CLI(c)
cli.parseOptions(args)
@ -17,16 +17,16 @@ if (cli.errored) {
function PrintHelp() {
console.log('')
console.log('Usage: casette <options> <files>')
console.log('Usage: eltro <options> <files>')
console.log('')
console.log('where <files> can either be a single file or a simple glob pattern.')
console.log('where <options> can be any of the following:')
console.log(' -r, --reporter - Specify the reporter to use.')
console.log(' Supported reporters: list, dot')
console.log('')
console.log('casette test/mytest.mjs')
console.log('casette dot test/*.mjs')
console.log('casette -r dot test/**/*.test.mjs')
console.log('eltro test/mytest.mjs')
console.log('eltro dot test/*.mjs')
console.log('eltro -r dot test/**/*.test.mjs')
process.exit(1)
}
@ -38,9 +38,9 @@ cli.processTargets().then(function() {
}
return cli.loadFiles()
.then(function() {
c.reporter = cli.reporter
e.reporter = cli.reporter
return c.run()
return e.run()
.catch(function(err) {
console.log('')
console.error('\x1b[31mUnknown error occured while running the tests\x1b[0m')

View file

@ -1,7 +1,7 @@
import Casette from './lib/casette.mjs'
import Eltro from './lib/eltro.mjs'
import assert from './lib/assert.mjs'
export {
Casette,
Eltro,
assert,
}

View file

@ -22,10 +22,10 @@ Test.prototype.skip = function() {
this.skipTest = true
}
function Casette() {
function Eltro() {
this.__timeout = 2000
this.reporter = 'list'
this.Casette = Casette
this.Eltro = Eltro
this.groups = new Map()
this.groupsFlat = []
this.tests = []
@ -36,9 +36,9 @@ function Casette() {
this.prefix = ''
}
Casette.prototype.begin = function() {
Eltro.prototype.begin = function() {
if (this.starting) {
console.warn('WARNING: Multiple calls to Casette.begin were done.')
console.warn('WARNING: Multiple calls to Eltro.begin were done.')
return
}
this.hasTests = false
@ -49,7 +49,7 @@ Casette.prototype.begin = function() {
this.tests.splice(0, this.tests.length)
}
Casette.prototype.__runTest = async function(stats, test) {
Eltro.prototype.__runTest = async function(stats, test) {
if (this.reporter === 'list') {
process.stdout.write(' \x1b[90m? ' + test.name + '\x1b[0m')
}
@ -163,7 +163,7 @@ Casette.prototype.__runTest = async function(stats, test) {
}
}
Casette.prototype.run = async function() {
Eltro.prototype.run = async function() {
if (this.reporter) {
console.log('')
console.log('')
@ -219,15 +219,15 @@ Casette.prototype.run = async function() {
}
}
Casette.prototype.setFilename = function(filename) {
Eltro.prototype.setFilename = function(filename) {
this.filename = filename
}
Casette.prototype.resetFilename = function() {
Eltro.prototype.resetFilename = function() {
this.filename = ''
}
Casette.prototype.describe = function(name, func) {
Eltro.prototype.describe = function(name, func) {
let before = this.prefix
if (before) {
this.prefix = before + ' ' + name
@ -238,7 +238,7 @@ Casette.prototype.describe = function(name, func) {
this.prefix = before
}
Casette.prototype.test = function(name, func) {
Eltro.prototype.test = function(name, func) {
let targetName = name
if (this.prefix) {
targetName = this.prefix + ' ' + name
@ -260,4 +260,4 @@ Casette.prototype.test = function(name, func) {
return test
}
export default new Casette()
export default new Eltro()

View file

@ -1,14 +1,14 @@
{
"name": "casette",
"name": "eltro",
"version": "0.9.2",
"description": "No-dependancy test framework for node",
"description": "Eltro is a small no-dependancy test framework for node",
"main": "index.mjs",
"scripts": {
"test": "node cli.mjs test/**/*.test.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TheThing/node-casette.git"
"url": "git+https://github.com/TheThing/node-eltro.git"
},
"keywords": [
"test",
@ -20,11 +20,11 @@
"author": "Jonatan Nilsson",
"license": "WTFPL",
"bugs": {
"url": "https://github.com/TheThing/node-casette/issues"
"url": "https://github.com/TheThing/node-eltro/issues"
},
"homepage": "https://github.com/TheThing/node-casette#readme",
"homepage": "https://github.com/TheThing/node-eltro#readme",
"bin": {
"casette": "./cli.mjs"
"eltro": "./cli.mjs"
},
"files": [
"index.mjs",

View file

@ -2,7 +2,7 @@ import util from 'util'
import assert from 'assert'
import assertExtended from '../lib/assert.mjs'
import c from '../lib/casette.mjs'
import e from '../lib/eltro.mjs'
const testLongObject = {
a: 1, b:2, c:3, d:4,
@ -11,37 +11,37 @@ const testLongObject = {
g: '32ghaiwugb23 238023'
}
c.describe('#notOk()', function() {
c.test('should exist', function() {
e.describe('#notOk()', function() {
e.test('should exist', function() {
assertExtended.ok(assertExtended.notOk)
})
c.test('should throw for true values', function() {
e.test('should throw for true values', function() {
assertExtended.throws(function() {
assertExtended.notOk(true)
}, assertExtended.AssertionError)
})
c.test('should pass for false values', function() {
e.test('should pass for false values', function() {
assertExtended.notOk(false)
assertExtended.notOk(null)
assertExtended.notOk(0)
})
})
c.describe('#isFulfilled()', function() {
c.test('should exist', function() {
e.describe('#isFulfilled()', function() {
e.test('should exist', function() {
assertExtended.ok(assertExtended.isFulfilled)
})
c.test('should throw for rejected promises', function() {
e.test('should throw for rejected promises', function() {
return assertExtended.isFulfilled(Promise.reject({}))
.catch((err) => {
assertExtended.ok(err.message.match(/promise fail/))
})
})
c.test('should properly parse rejected object response', function() {
e.test('should properly parse rejected object response', function() {
let assertMessage = util.inspect(testLongObject, {depth: 1}).replace(/\n /g, '')
assertMessage = assertMessage.slice(0, 64) + '...'
@ -51,7 +51,7 @@ c.describe('#isFulfilled()', function() {
)
})
c.test('should include error message if error', function() {
e.test('should include error message if error', function() {
const assertMessage = 'something something dark side'
return assertExtended.isFulfilled(Promise.reject(new Error(assertMessage)))
.catch((err) => {
@ -59,11 +59,11 @@ c.describe('#isFulfilled()', function() {
})
})
c.test('should pass for resolved promises', function() {
e.test('should pass for resolved promises', function() {
return assertExtended.isFulfilled(Promise.resolve())
})
c.test('should support custom message', function() {
e.test('should support custom message', function() {
const assertMessage = 'something something dark side'
return assertExtended.isFulfilled(Promise.reject({}), assertMessage)
.catch((err) => {
@ -71,7 +71,7 @@ c.describe('#isFulfilled()', function() {
})
})
c.test('should return result for the resolved promise', function() {
e.test('should return result for the resolved promise', function() {
const assertResult = {a: 1}
return assertExtended.isFulfilled(Promise.resolve(assertResult))
@ -79,12 +79,12 @@ c.describe('#isFulfilled()', function() {
})
})
c.describe('#isRejected()', function() {
c.test('should exist', function() {
e.describe('#isRejected()', function() {
e.test('should exist', function() {
assertExtended.ok(assertExtended.isRejected)
})
c.test('should throw for resolved promises', function() {
e.test('should throw for resolved promises', function() {
let hasFailed = false
return assertExtended.isRejected(Promise.resolve({}))
@ -97,7 +97,7 @@ c.describe('#isRejected()', function() {
})
})
c.test('should properly stringify objects', function() {
e.test('should properly stringify objects', function() {
let assertMessage = util.inspect(testLongObject, {depth: 1}).replace(/\n /g, '')
assertMessage = assertMessage.slice(0, 64) + '...'
@ -107,13 +107,13 @@ c.describe('#isRejected()', function() {
)
})
c.test('should support custom message', function() {
e.test('should support custom message', function() {
const assertMessage = 'something something dark side'
return assertExtended.isRejected(Promise.resolve({}), assertMessage)
.catch((err) => assertExtended.ok(err.message.match(assertMessage)))
})
c.test('should return result for the unresolved promise', function() {
e.test('should return result for the unresolved promise', function() {
const assertResult = {a: 1}
return assertExtended.isRejected(Promise.reject(assertResult))
@ -121,34 +121,34 @@ c.describe('#isRejected()', function() {
})
})
c.describe('#match()', function() {
c.test('should exist', function() {
e.describe('#match()', function() {
e.test('should exist', function() {
assertExtended.ok(assertExtended.match);
});
c.test('should throw if no match', function() {
e.test('should throw if no match', function() {
assertExtended.throws(function() {
assertExtended.match('a', /b/);
}, assertExtended.AssertionError);
});
c.test('should pass if matches', function() {
e.test('should pass if matches', function() {
assertExtended.match('a', /a/);
});
})
c.describe('#notMatch()', function() {
c.test('should exist', function() {
e.describe('#notMatch()', function() {
e.test('should exist', function() {
assertExtended.ok(assertExtended.notMatch);
});
c.test('should throw if match', function() {
e.test('should throw if match', function() {
assertExtended.throws(function() {
assertExtended.notMatch('a', /a/);
}, assertExtended.AssertionError);
});
c.test('should pass if not matches', function() {
e.test('should pass if not matches', function() {
assertExtended.notMatch('a', /b/);
});
})

View file

@ -1,11 +1,11 @@
import c from '../lib/casette.mjs'
import e from '../lib/eltro.mjs'
import assert from '../lib/assert.mjs'
import { CLI, getFiles, fileMatches } from '../lib/cli.mjs'
c.describe('CLI', function() {
e.describe('CLI', function() {
let cli = new CLI()
c.test('#constructor() give default options', function() {
e.test('#constructor() give default options', function() {
assert.strictEqual(cli.reporter, 'list')
assert.deepEqual(cli.targets, ['test/**'])
assert.deepEqual(cli.files, [])
@ -16,58 +16,58 @@ c.describe('CLI', function() {
* #parseOptions()
*****************************************/
c.describe('#parseOptions()', function() {
c.test('should not do anything if no options', function() {
e.describe('#parseOptions()', function() {
e.test('should not do anything if no options', function() {
cli.reporter = 'list'
cli.parseOptions([])
assert.strictEqual(cli.reporter, 'list')
assert.notOk(cli.errored)
})
c.test('should support overriding reporter with shorthand option', function() {
e.test('should support overriding reporter with shorthand option', function() {
cli.reporter = 'list'
cli.parseOptions(['-r', 'dot'])
assert.strictEqual(cli.reporter, 'dot')
assert.notOk(cli.errored)
})
c.test('should support overriding reporter with long option', function() {
e.test('should support overriding reporter with long option', function() {
cli.reporter = 'list'
cli.parseOptions(['--reporter', 'dot'])
assert.strictEqual(cli.reporter, 'dot')
assert.notOk(cli.errored)
})
c.test('should support reporter list', function() {
e.test('should support reporter list', function() {
cli.reporter = 'list'
cli.parseOptions(['-r', 'list'])
assert.strictEqual(cli.reporter, 'list')
assert.notOk(cli.errored)
})
c.test('should mark errored if missing reporter', function() {
e.test('should mark errored if missing reporter', function() {
cli.parseOptions(['--reporter'])
assert.ok(cli.errored)
})
c.test('should mark errored if invalid reporter', function() {
e.test('should mark errored if invalid reporter', function() {
cli.parseOptions(['--reporter', 'test'])
assert.ok(cli.errored)
})
c.test('should add file to targets', function() {
e.test('should add file to targets', function() {
cli.parseOptions(['test'])
assert.deepEqual(cli.targets, ['test'])
assert.notOk(cli.errored)
})
c.test('should add file to targets no matter where it is', function() {
e.test('should add file to targets no matter where it is', function() {
cli.parseOptions(['test', '-r', 'list', 'test2'])
assert.deepEqual(cli.targets, ['test', 'test2'])
assert.notOk(cli.errored)
})
c.test('should default add test to target if no target', function() {
e.test('should default add test to target if no target', function() {
cli.parseOptions(['-r', 'list'])
assert.deepEqual(cli.targets, ['test/**'])
assert.notOk(cli.errored)
@ -78,8 +78,8 @@ c.describe('CLI', function() {
* #processTargets()
*****************************************/
c.describe('#processTargets()', function() {
c.test('should mark errored if empty', async function() {
e.describe('#processTargets()', function() {
e.test('should mark errored if empty', async function() {
cli.targets = ['test/folder1/*.txt']
await cli.processTargets()
@ -87,7 +87,7 @@ c.describe('CLI', function() {
assert.ok(cli.errored)
})
c.test('should support direct file path if exists', async function() {
e.test('should support direct file path if exists', async function() {
cli.targets = ['test/folder1/sampletest1.temp.mjs']
await cli.processTargets()
@ -95,7 +95,7 @@ c.describe('CLI', function() {
assert.strictEqual(cli.files[0], 'test/folder1/sampletest1.temp.mjs')
})
c.test('should return all files in a directory', async function() {
e.test('should return all files in a directory', async function() {
cli.targets = ['test/folder1/']
await cli.processTargets()
@ -104,7 +104,7 @@ c.describe('CLI', function() {
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
c.test('should support start as folder substitute', async function() {
e.test('should support start as folder substitute', async function() {
cli.targets = ['*/folder1/']
await cli.processTargets()
@ -113,7 +113,7 @@ c.describe('CLI', function() {
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
c.test('should support grabbing only files in folder', async function() {
e.test('should support grabbing only files in folder', async function() {
cli.targets = ['test/*']
await cli.processTargets()
@ -124,7 +124,7 @@ c.describe('CLI', function() {
}
})
c.test('should support grabbing only pattern files in folder', async function() {
e.test('should support grabbing only pattern files in folder', async function() {
cli.targets = ['test/*.test.mjs']
await cli.processTargets()
@ -135,7 +135,7 @@ c.describe('CLI', function() {
}
})
c.test('should support multiple star pattern', async function() {
e.test('should support multiple star pattern', async function() {
cli.targets = ['test/*/*.mjs']
await cli.processTargets()
@ -161,7 +161,7 @@ c.describe('CLI', function() {
])
})
c.test('should support double star pattern', async function() {
e.test('should support double star pattern', async function() {
cli.targets = ['test/**/*.mjs']
await cli.processTargets()
@ -207,7 +207,7 @@ c.describe('CLI', function() {
})
})
c.test('should support double star pattern end', async function() {
e.test('should support double star pattern end', async function() {
cli.targets = ['test/**']
await cli.processTargets()
@ -255,7 +255,7 @@ c.describe('CLI', function() {
})
})
c.test('#fileMatches() should support filename matching with glob pattern', async function() {
e.test('#fileMatches() should support filename matching with glob pattern', async function() {
assert.ok(fileMatches('bla.test.mjs', '*.mjs'))
assert.ok(fileMatches('bla.test.mjs', '*test.mjs'))
assert.ok(fileMatches('bla.test.mjs', 'bla*.mjs'))

View file

@ -1,16 +1,16 @@
import c from '../lib/casette.mjs'
import e from '../lib/eltro.mjs'
import assert from '../lib/assert.mjs'
import { printError } from '../lib/cli.mjs'
let testsWereRun = false
function CreateT() {
const t = new c.Casette()
const t = new e.Eltro()
t.reporter = ''
return t
}
c.test('Casette describe should add prefix to the group tests', async function() {
e.test('Eltro describe should add prefix to the group tests', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertName = 'blabla'
@ -26,7 +26,7 @@ c.test('Casette describe should add prefix to the group tests', async function()
assert.strictEqual(t.groupsFlat[0].tests[0].name, assertPrefix + ' ' + assertName)
})
c.test('Casette describe should add prefix to individual tests', async function() {
e.test('Eltro describe should add prefix to individual tests', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertName = 'blabla'
@ -40,7 +40,7 @@ c.test('Casette describe should add prefix to individual tests', async function(
assert.strictEqual(t.tests[0].name, assertPrefix + ' ' + assertName)
})
c.test('Casette describe should support multiple describe', async function() {
e.test('Eltro describe should support multiple describe', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertPrefix2 = 'else'
@ -57,7 +57,7 @@ c.test('Casette describe should support multiple describe', async function() {
assert.strictEqual(t.tests[0].name, assertPrefix + ' ' + assertPrefix2 + ' ' + assertName)
})
c.test('Casette should run test', async function() {
e.test('Eltro should run test', async function() {
testsWereRun = true
let assertIsTrue = false
const t = CreateT()
@ -70,7 +70,7 @@ c.test('Casette should run test', async function() {
assert.strictEqual(assertIsTrue, true)
})
c.test('Casette should run promised test', async function() {
e.test('Eltro should run promised test', async function() {
testsWereRun = true
let assertIsTrue = false
const t = CreateT()
@ -86,7 +86,7 @@ c.test('Casette should run promised test', async function() {
assert.strictEqual(assertIsTrue, true)
})
c.test('Casette should support callback', async function() {
e.test('Eltro should support callback', async function() {
testsWereRun = true
let assertIsTrue = false
const t = CreateT()
@ -102,7 +102,7 @@ c.test('Casette should support callback', async function() {
assert.strictEqual(assertIsTrue, true)
})
c.test('Casette should support directly thrown errors', async function() {
e.test('Eltro should support directly thrown errors', async function() {
testsWereRun = true
const assertError = new Error()
const t = CreateT()
@ -115,7 +115,7 @@ c.test('Casette should support directly thrown errors', async function() {
assert.strictEqual(t.failedTests[0].error, assertError)
})
c.test('Casette should support promise rejected errors', async function() {
e.test('Eltro should support promise rejected errors', async function() {
testsWereRun = true
const assertError = new Error()
const t = CreateT()
@ -130,7 +130,7 @@ c.test('Casette should support promise rejected errors', async function() {
assert.strictEqual(t.failedTests[0].error, assertError)
})
c.test('Casette should support callback rejected errors', async function() {
e.test('Eltro should support callback rejected errors', async function() {
testsWereRun = true
const assertError = new Error()
const t = CreateT()
@ -143,7 +143,7 @@ c.test('Casette should support callback rejected errors', async function() {
assert.strictEqual(t.failedTests[0].error, assertError)
})
c.test('Casette should support timing out tests', async function() {
e.test('Eltro should support timing out tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
@ -154,7 +154,7 @@ c.test('Casette should support timing out tests', async function() {
assert.match(t.failedTests[0].error.message, /50ms/)
})
c.test('Casette should support timed out tests on late tests', async function() {
e.test('Eltro should support timed out tests on late tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
@ -169,7 +169,7 @@ c.test('Casette should support timed out tests on late tests', async function()
assert.match(t.failedTests[0].error.message, /50ms/)
})
c.test('Casette should support skipped tests', async function() {
e.test('Eltro should support skipped tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()

View file

@ -1,9 +0,0 @@
import { Casette as c, assert} from '../index.mjs'
c.describe('Array', function() {
c.describe('#indexOf()', function() {
c.test('should return -1 when value is not present', function() {
assert.equal([1,2,3].indexOf(4), -1)
})
})
})