2020-04-01 15:35:33 +00:00
|
|
|
import e from '../lib/eltro.mjs'
|
2020-03-31 17:27:36 +00:00
|
|
|
import assert from '../lib/assert.mjs'
|
|
|
|
import { printError } from '../lib/cli.mjs'
|
|
|
|
|
|
|
|
let testsWereRun = false
|
|
|
|
|
|
|
|
function CreateT() {
|
2020-04-01 15:35:33 +00:00
|
|
|
const t = new e.Eltro()
|
2020-03-31 17:27:36 +00:00
|
|
|
t.reporter = ''
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
e.test('Eltro should fail if tests are not within a group', function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.test('should throw', function() {})
|
|
|
|
}, function(e) {
|
|
|
|
assert.match(e.message, /outside/)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro describe should group tests', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const assertPrefix = 'something'
|
|
|
|
const assertName = 'blabla'
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe(assertPrefix, function() {
|
|
|
|
t.test(assertName, function() {})
|
|
|
|
})
|
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
assert.strictEqual(t.groups.length, 1)
|
|
|
|
assert.strictEqual(t.groups[0].tests.length, 1)
|
|
|
|
assert.strictEqual(t.groups[0].tests[0].name, assertPrefix + ' ' + assertName)
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
e.test('Eltro setFilename should activate a new for said file', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
2021-06-02 12:08:22 +00:00
|
|
|
const assertFilePrefix = 'testety'
|
2020-03-31 17:27:36 +00:00
|
|
|
const assertPrefix = 'something'
|
|
|
|
const assertName = 'blabla'
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.setFilename(assertFilePrefix)
|
2020-03-31 17:27:36 +00:00
|
|
|
t.describe(assertPrefix, function() {
|
|
|
|
t.test(assertName, function() {})
|
|
|
|
})
|
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
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)
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
e.test('Eltro describe should support nested describe', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const assertPrefix = 'something'
|
|
|
|
const assertPrefix2 = 'else'
|
|
|
|
const assertName = 'blabla'
|
2021-06-02 12:08:22 +00:00
|
|
|
const assertFile = 'asdf.js'
|
2020-03-31 17:27:36 +00:00
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.setFilename(assertFile)
|
2020-03-31 17:27:36 +00:00
|
|
|
t.describe(assertPrefix, function() {
|
|
|
|
t.describe(assertPrefix2, function() {
|
|
|
|
t.test(assertName, function() {})
|
|
|
|
})
|
|
|
|
})
|
2021-06-02 12:08:22 +00:00
|
|
|
t.resetFilename()
|
2020-03-31 17:27:36 +00:00
|
|
|
|
2021-06-02 12:08:22 +00:00
|
|
|
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)
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should run test', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
let assertIsTrue = false
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsTrue, true)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should run promised test', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
let assertIsTrue = false
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() {
|
|
|
|
return new Promise(function(res) {
|
|
|
|
assertIsTrue = true
|
|
|
|
res()
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsTrue, true)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support callback', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
let assertIsTrue = false
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) {
|
|
|
|
setTimeout(function() {
|
|
|
|
assertIsTrue = true
|
|
|
|
cb()
|
|
|
|
}, 25)
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsTrue, true)
|
|
|
|
})
|
|
|
|
|
2022-07-04 10:23:41 +00:00
|
|
|
e.test('Eltro should support custom cb with finish wrap', async function() {
|
|
|
|
let actualRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('a', function(cb) {
|
|
|
|
setImmediate(() => {
|
|
|
|
setImmediate(cb.finish(() => { actualRan++; }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('b', function(cb) {
|
|
|
|
setImmediate(() => {
|
|
|
|
setImmediate(cb.finish(() => { actualRan++; }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.test('c', function(cb) {
|
|
|
|
setImmediate(() => {
|
|
|
|
setImmediate(cb.finish(() => { actualRan++; }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.test('d', function(cb) {
|
|
|
|
setImmediate(() => {
|
|
|
|
setImmediate(cb.finish(() => { actualRan++; }))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(actualRan, 4)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support directly thrown errors', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() {
|
|
|
|
throw assertError
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.strictEqual(t.failedTests[0].error, assertError)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support promise rejected errors', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() {
|
|
|
|
return new Promise(function(res, rej) {
|
|
|
|
rej(assertError)
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.strictEqual(t.failedTests[0].error, assertError)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support callback rejected errors', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) {
|
|
|
|
cb(assertError)
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.strictEqual(t.failedTests[0].error, assertError)
|
|
|
|
})
|
|
|
|
|
2023-09-02 08:23:26 +00:00
|
|
|
e.test('Eltro should support capturing unknown errors outside scope', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) {
|
|
|
|
process.nextTick(function() {
|
|
|
|
console.log('throw')
|
|
|
|
throw assertError
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.strictEqual(t.failedTests[0].error, assertError)
|
|
|
|
})
|
|
|
|
|
2023-09-28 09:33:43 +00:00
|
|
|
|
|
|
|
e.test('Eltro should log an error if test is missing', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
|
|
|
t.describe('herpderp', function() {
|
|
|
|
t.test('blatest')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.match(t.failedTests[0].error.message, /herpderp/)
|
|
|
|
assert.match(t.failedTests[0].error.message, /blatest/)
|
|
|
|
assert.match(t.failedTests[0].error.message, /missing/)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should log an error if text is missing', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const assertError = new Error()
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
|
|
|
t.describe('herpderp', function() {
|
|
|
|
t.test()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.match(t.failedTests[0].error.message, /herpderp/)
|
|
|
|
assert.match(t.failedTests[0].error.message, /empty/)
|
|
|
|
assert.match(t.failedTests[0].error.message, /name/)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support timing out tests', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) { }).timeout(50)
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.ok(t.failedTests[0].error)
|
|
|
|
assert.match(t.failedTests[0].error.message, /50ms/)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support timed out tests on late tests', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) {
|
|
|
|
setTimeout(function() {
|
|
|
|
cb()
|
|
|
|
}, 100)
|
|
|
|
}).timeout(50)
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 1)
|
|
|
|
assert.ok(t.failedTests[0].error)
|
|
|
|
assert.match(t.failedTests[0].error.message, /50ms/)
|
|
|
|
})
|
|
|
|
|
2021-06-18 02:06:08 +00:00
|
|
|
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)
|
|
|
|
assert.match(t.failedTests[0].error.message, /25ms/)
|
|
|
|
})
|
|
|
|
|
2020-04-01 15:35:33 +00:00
|
|
|
e.test('Eltro should support skipped tests', async function() {
|
2020-03-31 17:27:36 +00:00
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() {
|
|
|
|
throw new Error('Should not be called')
|
|
|
|
}).skip()
|
|
|
|
})
|
2020-03-31 17:27:36 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
})
|
|
|
|
|
2020-04-01 16:42:13 +00:00
|
|
|
e.test('Eltro should support only tests', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertIsTrue = false
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
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()
|
|
|
|
})
|
2020-04-01 16:42:13 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsTrue, true)
|
|
|
|
})
|
|
|
|
|
2022-03-02 14:25:56 +00:00
|
|
|
e.test('Eltro should ignore only if ignoreOnly is specified', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertIsRun = 0
|
|
|
|
const t = CreateT()
|
|
|
|
|
|
|
|
t.ignoreOnly = true
|
|
|
|
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('a', function() { assertIsRun++ })
|
|
|
|
t.test('b', function() { assertIsRun++ }).only()
|
|
|
|
t.describe('sub', function() {
|
|
|
|
t.test('d', function() { assertIsRun++ })
|
|
|
|
t.only().test('c', function() { assertIsRun++ })
|
|
|
|
})
|
|
|
|
t.only().describe('sub2', function() {
|
|
|
|
t.test('d', function() { assertIsRun++ })
|
|
|
|
t.test('c', function() { assertIsRun++ })
|
|
|
|
})
|
|
|
|
t.describe('sub3', function() {
|
|
|
|
t.test('d', function() { assertIsRun++ })
|
|
|
|
t.test('c', function() { assertIsRun++ })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsRun, 8)
|
|
|
|
})
|
|
|
|
|
2021-06-18 02:06:08 +00:00
|
|
|
e.test('Eltro should support skipped tests in front of the test', async function() {
|
2020-04-01 16:42:13 +00:00
|
|
|
testsWereRun = true
|
2021-06-18 02:06:08 +00:00
|
|
|
let assertIsTrue = false
|
2020-04-01 16:42:13 +00:00
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-18 02:06:08 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
2021-06-02 12:08:22 +00:00
|
|
|
|
2020-04-01 16:42:13 +00:00
|
|
|
e.test('Eltro should support only tests in front of the test', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertIsTrue = false
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
|
|
|
|
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') })
|
|
|
|
})
|
|
|
|
|
2020-04-01 16:42:13 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertIsTrue, true)
|
|
|
|
})
|
|
|
|
|
2020-04-01 17:16:46 +00:00
|
|
|
e.test('Eltro should support timed out describes', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
|
2020-04-01 17:16:46 +00:00
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
t.timeout(10).describe('', function() {
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
2021-06-02 12:08:22 +00:00
|
|
|
|
2020-04-01 17:16:46 +00:00
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 2)
|
|
|
|
assert.ok(t.failedTests[0].error)
|
|
|
|
assert.match(t.failedTests[0].error.message, /10ms/)
|
|
|
|
assert.ok(t.failedTests[1].error)
|
|
|
|
assert.match(t.failedTests[1].error.message, /10ms/)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should support skipped tests in describe', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
t.skip().describe('', function() {
|
|
|
|
t.test('', function() { throw new Error('Should not be called') })
|
|
|
|
t.test('', function() { throw new Error('Should not be called') })
|
|
|
|
t.test('', function() { throw new Error('Should not be called') })
|
|
|
|
})
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertRan, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should have skip at higher importance than only', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
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') })
|
|
|
|
t.only().test('', function() { throw new Error('Should not be called') })
|
|
|
|
})
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
|
|
|
await t.run()
|
2021-06-02 12:08:22 +00:00
|
|
|
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)
|
2020-04-01 17:16:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should support nested skip in describe commands', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.skip().describe('', function() {
|
|
|
|
t.describe('', function() {
|
|
|
|
t.only().test('', function() { throw new Error('Should not be called') })
|
|
|
|
t.only().test('', function() { throw new Error('Should not be called') })
|
|
|
|
t.only().test('', function() { throw new Error('Should not be called') })
|
|
|
|
})
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
t.test('', function() { assertRan++ })
|
2020-04-01 17:16:46 +00:00
|
|
|
})
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0)
|
|
|
|
assert.strictEqual(assertRan, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should support only tests in front of the test', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
t.only().describe('', function() {
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('a', function() { throw new Error('Should not be called') })
|
|
|
|
})
|
|
|
|
t.test('c', function() { throw new Error('Should not be called') })
|
2020-04-01 17:16:46 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0, 'failed tests should be 0 but was ' + t.failedTests.length)
|
|
|
|
assert.strictEqual(assertRan, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should support nexted only tests in front of the test', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
let assertRan = 0
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.only().describe('', function() {
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
t.test('', function() { assertRan++ })
|
|
|
|
})
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.describe('', function() {
|
2021-06-02 12:08:22 +00:00
|
|
|
t.test('a', function() { throw new Error('Should not be called') })
|
2020-04-01 17:16:46 +00:00
|
|
|
})
|
2021-06-02 12:08:22 +00:00
|
|
|
t.test('c', function() { throw new Error('Should not be called') })
|
2020-04-01 17:16:46 +00:00
|
|
|
})
|
|
|
|
await t.run()
|
|
|
|
assert.strictEqual(t.failedTests.length, 0, 'failed tests should be 0 but was ' + t.failedTests.length)
|
|
|
|
assert.strictEqual(assertRan, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro should support nested timed out describes', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.timeout(10).describe('', function() {
|
|
|
|
t.describe('', function() {
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
|
|
|
})
|
2020-04-01 17:16:46 +00:00
|
|
|
t.describe('', 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)
|
|
|
|
assert.match(t.failedTests[0].error.message, /10ms/)
|
|
|
|
assert.ok(t.failedTests[1].error)
|
|
|
|
assert.match(t.failedTests[1].error.message, /10ms/)
|
|
|
|
})
|
|
|
|
|
|
|
|
e.test('Eltro nested timeout should work as expected', async function() {
|
|
|
|
testsWereRun = true
|
|
|
|
const t = CreateT()
|
|
|
|
t.begin()
|
2021-06-02 12:08:22 +00:00
|
|
|
t.describe('', function() {
|
|
|
|
t.timeout(50).describe('', function() {
|
|
|
|
t.timeout(10).describe('', function() {
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
|
|
|
t.test('', function(cb) { setTimeout(cb, 25) })
|
|
|
|
})
|
|
|
|
t.describe('', function() {
|
2020-04-01 17:16:46 +00:00
|
|
|
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)
|
|
|
|
assert.match(t.failedTests[0].error.message, /10ms/)
|
|
|
|
})
|
|
|
|
|
2020-03-31 17:27:36 +00:00
|
|
|
// Extra testing to make sure tests were run at all
|
|
|
|
process.on('exit', function(e) {
|
|
|
|
try {
|
2023-09-28 09:33:43 +00:00
|
|
|
assert.strictEqual(testsWereRun, true, 'Not all tests were run, remove all .only() and try again.')
|
2020-03-31 17:27:36 +00:00
|
|
|
} catch(err) {
|
|
|
|
printError(err)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
process.exit(e)
|
|
|
|
})
|