Updated readme and few other minor tests

master
Jonatan Nilsson 2020-04-01 15:50:55 +00:00
parent efc9c5901b
commit f9d6ca20d7
4 changed files with 88 additions and 88 deletions

View File

@ -1,42 +1,42 @@
# casette
Casette is a no-nonsense, no dependancy small test framework created to use in node 13 with ECM.
# eltro
Eltro is a no-nonsense, no dependancy small test framework created to use in node 13 with ECM.
# Installation
Install with npm globally:
```bash
$ npm install --global casette
$ npm install --global eltro
```
or as a development dependency for your project:
```bash
$ npm install --save-dev casette
$ npm install --save-dev eltro
```
# Getting started
```bash
$ npm install --save-dev casette
$ npm install --save-dev eltro
$ mkdir test
```
Next in your favourite editor, create `test/test.js`:
```node
import { Casette as c, assert} from 'casette'
import { Eltro as t, assert} from 'eltro'
c.describe('Array', function() {
c.describe('#indexOf()', function() {
c.test('should return -1 when value is not present', function() {
t.describe('Array', function() {
t.describe('#indexOf()', function() {
t.test('should return -1 when value is not present', function() {
assert.equal([1,2,3].indexOf(4), -1)
})
})
})
```
Set up a test script in package.json:
Set up a test script in packagt.json:
```json
"scripts": {
@ -59,7 +59,7 @@ $ npm test
# Assertions
Not only does casette 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:
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.notOk(value, [message])`: Assert value is not ok.
* `assert.match(value, test, [message])`: Check if value matches RegExp test.
@ -69,16 +69,16 @@ Not only does casette allow you to use any assertion library of your own choosin
# Asynchronous Code
Casette supports any type of asynchronous code testing. It can either be done by adding a parameter to the function (usually done) that gets called once the tests done but casette also supports promises.
Eltro supports any type of asynchronous code testing. It can either be done by adding a parameter to the function (usually done) that gets called once the tests done but eltro also supports promises.
Example of testing using done:
```node
import { Casette as c, assert} from 'casette'
import { Eltro as t, assert} from 'eltro'
c.describe('User', function() {
c.describe('#save()', function() {
c.test('should save without error', function(done) {
t.describe('User', function() {
t.describe('#save()', function() {
t.test('should save without error', function(done) {
var user = new User('Luna')
user.save(function(err) {
if (err) done(err)
@ -92,11 +92,11 @@ c.describe('User', function() {
Alternatively, just use the done() callback directly (which will handle an error argument, if it exists):
```node
import { Casette as c, assert} from 'casette'
import { Eltro as t, assert} from 'eltro'
c.describe('User', function() {
c.describe('#save()', function() {
c.test('should save without error', function(done) {
t.describe('User', function() {
t.describe('#save()', function() {
t.test('should save without error', function(done) {
var user = new User('Luna')
user.save(done)
})
@ -107,9 +107,9 @@ c.describe('User', function() {
Or another alternative is to use promises and return a promise directly:
```node
import { Casette as c, assert} from 'casette'
import { Eltro as t, assert} from 'eltro'
c.test('should complete this test', function(done) {
t.test('should complete this test', function(done) {
return new Promise(function(resolve, reject) {
reject(new Error('Uh oh, something went wrong'))
}).then(done)
@ -119,7 +119,7 @@ c.test('should complete this test', function(done) {
Which works well with `async/await` like so:
```node
c.test('async test', async function() {
t.test('async test', async function() {
let user = await User.find({ username: 'test' })
assert.ok(user)
})
@ -127,21 +127,21 @@ c.test('async test', async function() {
# Api
### c.test(message, func)
### t.test(message, func)
Queue up the `func` as a test with the specified message.
Queue up the `func` as a test with the specified messagt.
### c.describe(message, func)
### t.describe(message, func)
In case you wanna describe a bunch of tests, you can add them inside `func` and it will have the specified `message` prepended before every test:
```node
import { Casette as c, assert} from 'casette'
import { Eltro as t, assert} from 'eltro'
function someFunction() { return true }
c.test('#someFunction()', function() {
c.test('should always return true', function() {
t.test('#someFunction()', function() {
t.test('should always return true', function() {
assert.strictEqual(someFunction(), true)
assert.strictEqual(someFunction(), true)
assert.strictEqual(someFunction(), true)
@ -155,22 +155,22 @@ will output:
#someFunction() should always return true
```
### c.test(...).skip()
### t.test(...).skip()
You can skip tests easily by adding `.skip()` after the test like so:
```node
c.test('Skip due to something being broken', function() {
t.test('Skip due to something being broken', function() {
BrokenFunction()
}).skip()
```
### c.test(...).timeout(dur)
### t.test(...).timeout(dur)
Tests can take a long time. By default, casette will cancel a test if it takes longer than 2 seconds. You can however override this by calling the timeout function after the test with the specified duration in milliseconds like so:
Tests can take a long timt. By default, eltro will cancel a test if it takes longer than 2 seconds. You can however override this by calling the timeout function after the test with the specified duration in milliseconds like so:
```node
c.test('This is a really long test', async function() {
t.test('This is a really long test', async function() {
await DoSomethingForReallyLongTime()
}).timeout(5000) // 5 seconds
```

View File

@ -1,7 +1,7 @@
{
"name": "eltro",
"version": "0.9.0",
"description": "Eltro is a small no-dependancy test framework for node",
"description": "Eltro is a tiny no-dependancy test framework for node",
"main": "index.mjs",
"scripts": {
"test": "node cli.mjs test/**/*.test.mjs"

View File

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

View File

@ -1,11 +1,11 @@
import e from '../lib/eltro.mjs'
import t from '../lib/eltro.mjs'
import assert from '../lib/assert.mjs'
import { CLI, getFiles, fileMatches } from '../lib/cli.mjs'
e.describe('CLI', function() {
t.describe('CLI', function() {
let cli = new CLI()
e.test('#constructor() give default options', function() {
t.test('#constructor() give default options', function() {
assert.strictEqual(cli.reporter, 'list')
assert.deepEqual(cli.targets, ['test/**'])
assert.deepEqual(cli.files, [])
@ -16,69 +16,69 @@ e.describe('CLI', function() {
* #parseOptions()
*****************************************/
e.describe('#parseOptions()', function() {
e.test('should not do anything if no options', function() {
t.describe('#parseOptions()', function() {
t.test('should not do anything if no options', function() {
cli.reporter = 'list'
cli.parseOptions([])
assert.strictEqual(cli.reporter, 'list')
assert.notOk(cli.errored)
})
e.test('should support overriding reporter with shorthand option', function() {
t.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)
})
e.test('should support overriding reporter with long option', function() {
t.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)
})
e.test('should support reporter list', function() {
t.test('should support reporter list', function() {
cli.reporter = 'list'
cli.parseOptions(['-r', 'list'])
assert.strictEqual(cli.reporter, 'list')
assert.notOk(cli.errored)
})
e.test('should mark errored if missing reporter', function() {
t.test('should mark errored if missing reporter', function() {
cli.parseOptions(['--reporter'])
assert.ok(cli.errored)
})
e.test('should mark errored if invalid reporter', function() {
t.test('should mark errored if invalid reporter', function() {
cli.parseOptions(['--reporter', 'test'])
assert.ok(cli.errored)
})
e.test('should add file to targets', function() {
t.test('should add file to targets', function() {
cli.parseOptions(['test'])
assert.deepEqual(cli.targets, ['test'])
assert.notOk(cli.errored)
})
e.test('should add file to targets no matter where it is', function() {
t.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)
})
e.test('should default add test to target if no target', function() {
t.test('should default add test to target if no target', function() {
cli.parseOptions(['-r', 'list'])
assert.deepEqual(cli.targets, ['test/**'])
assert.notOk(cli.errored)
})
e.test('should mark errored if invalid shorthand option', function() {
t.test('should mark errored if invalid shorthand option', function() {
cli.parseOptions(['-A'])
assert.ok(cli.errored)
})
e.test('should mark errored if invalid longhand option', function() {
t.test('should mark errored if invalid longhand option', function() {
cli.parseOptions(['--asdf'])
assert.ok(cli.errored)
})
@ -88,8 +88,8 @@ e.describe('CLI', function() {
* #processTargets()
*****************************************/
e.describe('#processTargets()', function() {
e.test('should mark errored if empty', async function() {
t.describe('#processTargets()', function() {
t.test('should mark errored if empty', async function() {
cli.targets = ['test/folder1/*.txt']
await cli.processTargets()
@ -97,7 +97,7 @@ e.describe('CLI', function() {
assert.ok(cli.errored)
})
e.test('should support direct file path if exists', async function() {
t.test('should support direct file path if exists', async function() {
cli.targets = ['test/folder1/sampletest1.temp.mjs']
await cli.processTargets()
@ -105,7 +105,7 @@ e.describe('CLI', function() {
assert.strictEqual(cli.files[0], 'test/folder1/sampletest1.temp.mjs')
})
e.test('should return all files in a directory', async function() {
t.test('should return all files in a directory', async function() {
cli.targets = ['test/folder1/']
await cli.processTargets()
@ -114,7 +114,7 @@ e.describe('CLI', function() {
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
e.test('should support start as folder substitute', async function() {
t.test('should support start as folder substitute', async function() {
cli.targets = ['*/folder1/']
await cli.processTargets()
@ -123,7 +123,7 @@ e.describe('CLI', function() {
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
e.test('should support grabbing only files in folder', async function() {
t.test('should support grabbing only files in folder', async function() {
cli.targets = ['test/*']
await cli.processTargets()
@ -134,7 +134,7 @@ e.describe('CLI', function() {
}
})
e.test('should support grabbing only pattern files in folder', async function() {
t.test('should support grabbing only pattern files in folder', async function() {
cli.targets = ['test/*.test.mjs']
await cli.processTargets()
@ -145,7 +145,7 @@ e.describe('CLI', function() {
}
})
e.test('should support multiple star pattern', async function() {
t.test('should support multiple star pattern', async function() {
cli.targets = ['test/*/*.mjs']
await cli.processTargets()
@ -171,7 +171,7 @@ e.describe('CLI', function() {
])
})
e.test('should support double star pattern', async function() {
t.test('should support double star pattern', async function() {
cli.targets = ['test/**/*.mjs']
await cli.processTargets()
@ -217,7 +217,7 @@ e.describe('CLI', function() {
})
})
e.test('should support double star pattern end', async function() {
t.test('should support double star pattern end', async function() {
cli.targets = ['test/**']
await cli.processTargets()
@ -265,7 +265,7 @@ e.describe('CLI', function() {
})
})
e.test('#fileMatches() should support filename matching with glob pattern', async function() {
t.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'))