Revamped and reworked entire grouping and testing. Added better support for nested groups. Fixed a bunch of bugs.

This commit is contained in:
Jonatan Nilsson 2021-06-02 12:08:22 +00:00
parent d7d7f1526e
commit 7c4829c36b
5 changed files with 328 additions and 214 deletions

View file

@ -1,5 +1,5 @@
# eltro
Eltro is a no-nonsense, no dependancy small test framework created to use in node 13 with ECM.
Eltro is a no-nonsense, no dependancy, small test framework created to use in node 13 or higher using ECM modules.
# Installation
@ -22,7 +22,7 @@ $ npm install --save-dev eltro
$ mkdir test
```
Next in your favourite editor, create `test/test.js`:
Next in your favourite editor, create `test/test.mjs`:
```node
import { Eltro as t, assert} from 'eltro'
@ -36,11 +36,11 @@ t.describe('Array', function() {
})
```
Set up a test script in packagt.json:
Set up a test script in package.json:
```json
"scripts": {
"test": "mocha"
"test": "eltro"
}
```

View file

@ -1,9 +1,50 @@
import { printError } from './cli.mjs'
function Group(name) {
function Group(e, name) {
this.e = e
this.name = name
this.hasExclusive = false
this.parent = null
this.groups = []
this.tests = []
this.customTimeout = null
this.skipTest = false
this.isExclusive = false
}
Group.prototype.timeout = function(time) {
this.customTimeout = time
}
Group.prototype.skip = function() {
this.skipTest = true
}
Group.prototype.__hasonly = function(markHas) {
if (this.skipTest) return
// Set hasExclusive with either mark or existing value
// Some groups might have .only() but that doesn't mean
// the children have .only() buut they should still be run
this.hasExclusive = this.hasExclusive || markHas
// Travel upwards to the root mark all the groups along the way
let g = this.parent
while (g) {
// If the parent has skipped marked, we definitely don't wanna
// mark that we have tests with exclusivity on.
if (g.skipTest) return
g.hasExclusive = true
g = g.parent
}
this.e.hasExclusive = true
}
Group.prototype.only = function() {
this.isExclusive = true
this.__hasonly(false)
}
function Test(e, group, name, func) {
@ -26,7 +67,8 @@ Test.prototype.skip = function() {
}
Test.prototype.only = function() {
this.e.hasExclusive = this.group.hasExclusive = this.isExclusive = true
this.isExclusive = true
this.group.__hasonly(true)
}
function Eltro() {
@ -34,10 +76,9 @@ function Eltro() {
this.hasExclusive = false
this.reporter = 'list'
this.Eltro = Eltro
this.groups = new Map()
this.groupsFlat = []
this.fileGroupMap = new Map()
this.groups = []
this.activeGroup = null
this.tests = []
this.failedTests = []
this.hasTests = false
this.starting = false
@ -64,8 +105,7 @@ Eltro.prototype.begin = function() {
this.starting = true
this.filename = ''
this.prefix = ''
this.groups.clear()
this.tests.splice(0, this.tests.length)
this.fileGroupMap.clear()
}
Eltro.prototype.__runTest = async function(stats, test) {
@ -182,6 +222,23 @@ Eltro.prototype.__runTest = async function(stats, test) {
}
}
Eltro.prototype.__runGroup = async function(g, stats) {
if (g.tests.length) {
if (this.reporter === 'list') {
console.log(' ' + g.name)
}
}
for (let x = 0; x < g.tests.length; x++) {
if (!g.tests[x].skipTest && g.tests[x].isExclusive === g.hasExclusive) {
await this.__runTest(stats, g.tests[x])
}
}
for (let x = 0; x < g.groups.length; x++) {
if (!g.groups[x].skipTest && g.hasExclusive === (g.groups[x].hasExclusive || g.groups[x].isExclusive))
await this.__runGroup(g.groups[x], stats)
}
}
Eltro.prototype.run = async function() {
if (this.reporter) {
console.log('')
@ -195,24 +252,12 @@ Eltro.prototype.run = async function() {
}
let start = process.hrtime()
for (let i = 0; i < this.groupsFlat.length; i++) {
let g = this.groupsFlat[i];
if (g.hasExclusive === this.hasExclusive) {
if (this.reporter === 'list') {
console.log(' ' + g.name)
}
for (let x = 0; x < g.tests.length; x++) {
await this.__runTest(stats, g.tests[x])
}
for (let i = 0; i < this.groups.length; i++) {
if (!this.groups[i].skipTest && this.hasExclusive === (this.groups[i].hasExclusive || this.groups[i].isExclusive)) {
await this.__runGroup(this.groups[i], stats)
}
}
for (let x = 0; x < this.tests.length; x++) {
if (this.tests[x].isExclusive === this.hasExclusive) {
await this.__runTest(stats, this.tests[x])
}
}
let end = process.hrtime(start)
if (this.reporter) {
@ -232,10 +277,7 @@ Eltro.prototype.run = async function() {
if (this.failedTests.length) {
for (let x = 0; x < this.failedTests.length; x++) {
let test = this.failedTests[x];
console.log(' ' + (x + 1) + ') '
+ (test.group ? test.group.name + ': ' : '' )
+ test.name + ':'
)
console.log(' ' + (x + 1) + ') ' + test.name + ':')
printError(test.error)
}
}
@ -243,34 +285,49 @@ Eltro.prototype.run = async function() {
}
Eltro.prototype.setFilename = function(filename) {
this.filename = filename
if (!this.fileGroupMap.has(filename)) {
let g = new Group(this, filename + ':')
this.groups.push(g)
this.fileGroupMap.set(filename, g)
}
this.activeGroup = this.fileGroupMap.get(filename)
}
Eltro.prototype.resetFilename = function() {
this.filename = ''
this.activeGroup = null
}
Eltro.prototype.describe = function(name, func) {
let before = this.prefix
let before = this.activeGroup
// Store and set the temporary test values for entire group
let beforeCurrent = this.describeTemporary
this.describeTemporary = {
timeout: this.temporary.timeout || beforeCurrent.timeout,
skip: this.temporary.skip || beforeCurrent.skip,
only: this.temporary.only || beforeCurrent.only,
}
this.temporary.timeout = 0
this.temporary.skip = this.temporary.only = false
let prefix = before ? before.name + ' ' : ''
this.activeGroup = new Group(this, prefix + name)
if (before) {
this.prefix = before + ' ' + name
before.groups.push(this.activeGroup)
this.activeGroup.parent = before
this.activeGroup.customTimeout = before.customTimeout
} else {
this.prefix = name
this.groups.push(this.activeGroup)
}
if (this.temporary.timeout) {
this.activeGroup.timeout(this.temporary.timeout)
this.temporary.timeout = 0
}
if (this.temporary.skip) {
this.activeGroup.skip()
this.temporary.skip = false
}
if (this.temporary.only) {
this.activeGroup.only()
this.temporary.only = false
}
func()
this.describeTemporary = beforeCurrent
this.prefix = before
this.activeGroup = before
}
Eltro.prototype.timeout = function(time) {
@ -289,36 +346,25 @@ Eltro.prototype.only = function() {
}
Eltro.prototype.test = function(name, func) {
let targetName = name
if (this.prefix) {
targetName = this.prefix + ' ' + name
if (!this.activeGroup) {
throw new Error('Tests outside groups are not allowed.')
}
this.hasTests = true
let group = this
if (this.filename) {
if (!this.groups.has(this.filename)) {
let g = new Group(this.filename)
this.groupsFlat.push(g)
this.groups.set(this.filename, g)
}
group = this.groups.get(this.filename)
}
let test = new Test(this, group, targetName, func)
group.tests.push(test)
let test = new Test(this, this.activeGroup, this.activeGroup.name + ' ' + name, func)
this.activeGroup.tests.push(test)
if ((this.temporary.only || this.describeTemporary.only) && !this.temporary.skip && !this.describeTemporary.skip) {
if (this.temporary.only && !this.temporary.skip) {
test.only()
this.temporary.only = false
} else if (this.temporary.only) {
this.temporary.only = false
}
if (this.temporary.skip || this.describeTemporary.skip) {
if (this.temporary.skip) {
test.skip()
this.temporary.skip = false
}
if (this.temporary.timeout || this.describeTemporary.timeout) {
test.timeout(this.temporary.timeout || this.describeTemporary.timeout)
if (this.temporary.timeout || this.activeGroup.customTimeout) {
test.timeout(this.temporary.timeout || this.activeGroup.customTimeout)
this.temporary.timeout = 0
}
return test

View file

@ -1,6 +1,6 @@
{
"name": "eltro",
"version": "0.9.1",
"version": "1.0.0",
"description": "Eltro is a tiny no-dependancy test framework for node",
"main": "index.mjs",
"scripts": {

View file

@ -6,10 +6,11 @@ t.describe('CLI', function() {
let cli = new CLI()
t.test('#constructor() give default options', function() {
assert.strictEqual(cli.reporter, 'list')
assert.deepEqual(cli.targets, ['test/**'])
assert.deepEqual(cli.files, [])
assert.notOk(cli.errored)
let cliTest = new CLI()
assert.strictEqual(cliTest.reporter, 'list')
assert.deepEqual(cliTest.targets, ['test/**'])
assert.deepEqual(cliTest.files, [])
assert.notOk(cliTest.errored)
})
/*****************************************
@ -110,6 +111,7 @@ t.describe('CLI', function() {
await cli.processTargets()
assert.strictEqual(cli.files.length, 2)
cli.files.sort()
assert.strictEqual(cli.files[0], 'test/folder1/sampletest1.temp.mjs')
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
@ -119,6 +121,7 @@ t.describe('CLI', function() {
await cli.processTargets()
assert.strictEqual(cli.files.length, 2)
cli.files.sort()
assert.strictEqual(cli.files[0], 'test/folder1/sampletest1.temp.mjs')
assert.strictEqual(cli.files[1], 'test/folder1/sampletest2.temp.mjs')
})
@ -187,24 +190,12 @@ t.describe('CLI', function() {
}
for (let i = 0; i < cli.files.length; i++) {
if (cli.files[i] === 'test/folder1/sampletest1.temp.mjs') {
found.sampletest1 = true
}
if (cli.files[i] === 'test/folder1/sampletest2.temp.mjs') {
found.sampletest2 = true
}
if (cli.files[i] === 'test/folder2/sampletest3.temp.mjs') {
found.sampletest3 = true
}
if (cli.files[i] === 'test/folder2/sampletest4.temp.mjs') {
found.sampletest4 = true
}
if (cli.files[i] === 'test/folder2/sampletest5.temp.txt') {
found.sampletest5 = true
}
if (cli.files[i] === 'test/cli.test.mjs') {
found.cli = true
}
found.sampletest1 = found.sampletest1 || cli.files[i] === 'test/folder1/sampletest1.temp.mjs'
found.sampletest2 = found.sampletest2 || cli.files[i] === 'test/folder1/sampletest2.temp.mjs'
found.sampletest3 = found.sampletest3 || cli.files[i] === 'test/folder2/sampletest3.temp.mjs'
found.sampletest4 = found.sampletest4 || cli.files[i] === 'test/folder2/sampletest4.temp.mjs'
found.sampletest5 = found.sampletest5 || cli.files[i] === 'test/folder2/sampletest5.temp.txt'
found.cli = found.cli || cli.files[i] === 'test/cli.test.mjs'
}
assert.deepEqual(found, {
@ -233,24 +224,12 @@ t.describe('CLI', function() {
}
for (let i = 0; i < cli.files.length; i++) {
if (cli.files[i] === 'test/folder1/sampletest1.temp.mjs') {
found.sampletest1 = true
}
if (cli.files[i] === 'test/folder1/sampletest2.temp.mjs') {
found.sampletest2 = true
}
if (cli.files[i] === 'test/folder2/sampletest3.temp.mjs') {
found.sampletest3 = true
}
if (cli.files[i] === 'test/folder2/sampletest4.temp.mjs') {
found.sampletest4 = true
}
if (cli.files[i] === 'test/folder2/sampletest5.temp.txt') {
found.sampletest5 = true
}
if (cli.files[i] === 'test/cli.test.mjs') {
found.cli = true
}
found.sampletest1 = found.sampletest1 || cli.files[i] === 'test/folder1/sampletest1.temp.mjs'
found.sampletest2 = found.sampletest2 || cli.files[i] === 'test/folder1/sampletest2.temp.mjs'
found.sampletest3 = found.sampletest3 || cli.files[i] === 'test/folder2/sampletest3.temp.mjs'
found.sampletest4 = found.sampletest4 || cli.files[i] === 'test/folder2/sampletest4.temp.mjs'
found.sampletest5 = found.sampletest5 || cli.files[i] === 'test/folder2/sampletest5.temp.txt'
found.cli = found.cli || cli.files[i] === 'test/cli.test.mjs'
}
assert.deepEqual(found, {

View file

@ -10,23 +10,18 @@ function CreateT() {
return t
}
e.test('Eltro describe should add prefix to the group tests', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertName = 'blabla'
e.test('Eltro should fail if tests are not within a group', function() {
assert.throws(function() {
const t = CreateT()
t.begin()
t.setFilename('test')
t.describe(assertPrefix, function() {
t.test(assertName, function() {})
t.test('should throw', function() {})
}, function(e) {
assert.match(e.message, /outside/)
return true
})
assert.strictEqual(t.groupsFlat.length, 1)
assert.strictEqual(t.groupsFlat[0].tests.length, 1)
assert.strictEqual(t.groupsFlat[0].tests[0].name, assertPrefix + ' ' + assertName)
})
e.test('Eltro describe should add prefix to individual tests', async function() {
e.test('Eltro describe should group tests', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertName = 'blabla'
@ -36,25 +31,50 @@ e.test('Eltro describe should add prefix to individual tests', async function()
t.test(assertName, function() {})
})
assert.strictEqual(t.tests.length, 1)
assert.strictEqual(t.tests[0].name, assertPrefix + ' ' + assertName)
assert.strictEqual(t.groups.length, 1)
assert.strictEqual(t.groups[0].tests.length, 1)
assert.strictEqual(t.groups[0].tests[0].name, assertPrefix + ' ' + assertName)
})
e.test('Eltro describe should support multiple describe', async function() {
e.test('Eltro setFilename should activate a new for said file', async function() {
testsWereRun = true
const assertFilePrefix = 'testety'
const assertPrefix = 'something'
const assertName = 'blabla'
const t = CreateT()
t.begin()
t.setFilename(assertFilePrefix)
t.describe(assertPrefix, function() {
t.test(assertName, function() {})
})
assert.strictEqual(t.groups.length, 1)
assert.strictEqual(t.groups[0].tests.length, 0)
assert.strictEqual(t.groups[0].groups.length, 1)
assert.strictEqual(t.groups[0].groups[0].tests.length, 1)
assert.strictEqual(t.groups[0].groups[0].tests[0].name, assertFilePrefix + ': ' + assertPrefix + ' ' + assertName)
})
e.test('Eltro describe should support nested describe', async function() {
testsWereRun = true
const assertPrefix = 'something'
const assertPrefix2 = 'else'
const assertName = 'blabla'
const assertFile = 'asdf.js'
const t = CreateT()
t.begin()
t.setFilename(assertFile)
t.describe(assertPrefix, function() {
t.describe(assertPrefix2, function() {
t.test(assertName, function() {})
})
})
t.resetFilename()
assert.strictEqual(t.tests.length, 1)
assert.strictEqual(t.tests[0].name, assertPrefix + ' ' + assertPrefix2 + ' ' + assertName)
assert.strictEqual(t.groups.length, 1)
assert.strictEqual(t.groups[0].groups.length, 1)
assert.strictEqual(t.groups[0].groups[0].groups.length, 1)
assert.strictEqual(t.groups[0].groups[0].groups[0].tests[0].name, assertFile + ': ' + assertPrefix + ' ' + assertPrefix2 + ' ' + assertName)
})
e.test('Eltro should run test', async function() {
@ -62,9 +82,30 @@ e.test('Eltro should run test', async function() {
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function() {
assertIsTrue = true
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
})
e.test('Eltro should run tests in nested groups', async function() {
testsWereRun = true
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('1', function() {
t.describe('2', function() {
t.describe('3', function() {
t.test('', function() {
assertIsTrue = true
})
})
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
@ -75,12 +116,14 @@ e.test('Eltro should run promised test', async function() {
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function() {
return new Promise(function(res) {
assertIsTrue = true
res()
})
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
@ -91,11 +134,13 @@ e.test('Eltro should support callback', async function() {
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function(cb) {
setTimeout(function() {
assertIsTrue = true
cb()
}, 50)
}, 25)
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
@ -107,9 +152,11 @@ e.test('Eltro should support directly thrown errors', async function() {
const assertError = new Error()
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function() {
throw assertError
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.strictEqual(t.failedTests[0].error, assertError)
@ -120,11 +167,13 @@ e.test('Eltro should support promise rejected errors', async function() {
const assertError = new Error()
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function() {
return new Promise(function(res, rej) {
rej(assertError)
})
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.strictEqual(t.failedTests[0].error, assertError)
@ -135,9 +184,11 @@ e.test('Eltro should support callback rejected errors', async function() {
const assertError = new Error()
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function(cb) {
cb(assertError)
})
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.strictEqual(t.failedTests[0].error, assertError)
@ -147,7 +198,9 @@ e.test('Eltro should support timing out tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function(cb) { }).timeout(50)
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.ok(t.failedTests[0].error)
@ -158,11 +211,13 @@ e.test('Eltro should support timed out tests on late tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function(cb) {
setTimeout(function() {
cb()
}, 100)
}).timeout(50)
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.ok(t.failedTests[0].error)
@ -173,9 +228,11 @@ e.test('Eltro should support skipped tests', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('', function() {
throw new Error('Should not be called')
}).skip()
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
})
@ -185,9 +242,11 @@ e.test('Eltro should support only tests', async function() {
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('a', function() { throw new Error('Should not be called') })
t.test('b', function() { throw new Error('Should not be called') })
t.test('c', function() { assertIsTrue = true }).only()
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
@ -197,8 +256,12 @@ e.test('Eltro should support timed out tests in front', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.timeout(25).test('', function(cb) { setTimeout(cb, 50) })
t.test('', function(cb) { setTimeout(cb, 50) })
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.ok(t.failedTests[0].error)
@ -210,8 +273,11 @@ e.test('Eltro should support skipped tests in front of the test', async function
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.skip().test('', function() { throw new Error('Should not be called') })
t.test('', function() { assertIsTrue = true })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
@ -222,9 +288,13 @@ e.test('Eltro should support only tests in front of the test', async function()
let assertIsTrue = false
const t = CreateT()
t.begin()
t.describe('', function() {
t.test('a', function() { throw new Error('Should not be called') })
t.only().test('b', function() { assertIsTrue = true })
t.test('c', function() { throw new Error('Should not be called') })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertIsTrue, true)
@ -234,6 +304,8 @@ e.test('Eltro should support timed out describes', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.timeout(10).describe('', function() {
t.test('', function(cb) { setTimeout(cb, 25) })
t.test('', function(cb) { setTimeout(cb, 25) })
@ -242,6 +314,8 @@ e.test('Eltro should support timed out describes', async function() {
t.test('', function(cb) { setTimeout(cb, 25) })
})
t.test('', function(cb) { setTimeout(cb, 25) })
})
await t.run()
assert.strictEqual(t.failedTests.length, 2)
assert.ok(t.failedTests[0].error)
@ -255,6 +329,7 @@ e.test('Eltro should support skipped tests in describe', async function() {
let assertRan = 0
const t = CreateT()
t.begin()
t.describe('', function() {
t.skip().describe('', function() {
t.test('', function() { throw new Error('Should not be called') })
t.test('', function() { throw new Error('Should not be called') })
@ -264,6 +339,7 @@ e.test('Eltro should support skipped tests in describe', async function() {
t.test('', function() { assertRan++ })
})
t.test('', function() { assertRan++ })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertRan, 2)
@ -274,6 +350,7 @@ e.test('Eltro should have skip at higher importance than only', async function()
let assertRan = 0
const t = CreateT()
t.begin()
t.describe('', function() {
t.skip().describe('', function() {
t.only().test('', function() { throw new Error('Should not be called') })
t.only().test('', function() { throw new Error('Should not be called') })
@ -283,9 +360,10 @@ e.test('Eltro should have skip at higher importance than only', async function()
t.test('', function() { assertRan++ })
})
t.test('', function() { assertRan++ })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertRan, 2)
assert.strictEqual(t.failedTests.length, 0, 'failed tests should be 0 but was ' + t.failedTests.length)
assert.strictEqual(assertRan, 2, 'tests run should be two but was ' + assertRan)
})
e.test('Eltro should support nested skip in describe commands', async function() {
@ -293,6 +371,7 @@ e.test('Eltro should support nested skip in describe commands', async function()
let assertRan = 0
const t = CreateT()
t.begin()
t.describe('', function() {
t.skip().describe('', function() {
t.describe('', function() {
t.only().test('', function() { throw new Error('Should not be called') })
@ -304,6 +383,7 @@ e.test('Eltro should support nested skip in describe commands', async function()
t.test('', function() { assertRan++ })
})
t.test('', function() { assertRan++ })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0)
assert.strictEqual(assertRan, 2)
@ -314,6 +394,7 @@ e.test('Eltro should support only tests in front of the test', async function()
let assertRan = 0
const t = CreateT()
t.begin()
t.describe('', function() {
t.only().describe('', function() {
t.test('', function() { assertRan++ })
t.test('', function() { assertRan++ })
@ -322,6 +403,7 @@ e.test('Eltro should support only tests in front of the test', async function()
t.test('a', function() { throw new Error('Should not be called') })
})
t.test('c', function() { throw new Error('Should not be called') })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0, 'failed tests should be 0 but was ' + t.failedTests.length)
assert.strictEqual(assertRan, 2)
@ -332,6 +414,7 @@ e.test('Eltro should support nexted only tests in front of the test', async func
let assertRan = 0
const t = CreateT()
t.begin()
t.describe('', function() {
t.only().describe('', function() {
t.describe('', function() {
t.test('', function() { assertRan++ })
@ -342,6 +425,7 @@ e.test('Eltro should support nexted only tests in front of the test', async func
t.test('a', function() { throw new Error('Should not be called') })
})
t.test('c', function() { throw new Error('Should not be called') })
})
await t.run()
assert.strictEqual(t.failedTests.length, 0, 'failed tests should be 0 but was ' + t.failedTests.length)
assert.strictEqual(assertRan, 2)
@ -351,6 +435,7 @@ e.test('Eltro should support nested timed out describes', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.timeout(10).describe('', function() {
t.describe('', function() {
t.test('', function(cb) { setTimeout(cb, 25) })
@ -361,6 +446,7 @@ e.test('Eltro should support nested timed out describes', async function() {
t.test('', function(cb) { setTimeout(cb, 25) })
})
t.test('', function(cb) { setTimeout(cb, 25) })
})
await t.run()
assert.strictEqual(t.failedTests.length, 2)
assert.ok(t.failedTests[0].error)
@ -373,6 +459,7 @@ e.test('Eltro nested timeout should work as expected', async function() {
testsWereRun = true
const t = CreateT()
t.begin()
t.describe('', function() {
t.timeout(50).describe('', function() {
t.timeout(10).describe('', function() {
t.test('', function(cb) { setTimeout(cb, 25) })
@ -383,6 +470,7 @@ e.test('Eltro nested timeout should work as expected', async function() {
t.test('', function(cb) { setTimeout(cb, 25) })
})
t.test('', function(cb) { setTimeout(cb, 25) })
})
await t.run()
assert.strictEqual(t.failedTests.length, 1)
assert.ok(t.failedTests[0].error)
@ -394,6 +482,7 @@ process.on('exit', function(e) {
try {
assert.strictEqual(testsWereRun, true)
} catch(err) {
console.log('Checking if tests were run at all failed:')
printError(err)
process.exit(1)
}