Allow returning more than one Assert per function

pull/7/head
yann300 7 years ago
parent 085fd5792e
commit 3ebe6fbded
  1. 28
      src/testRunner.js

@ -59,37 +59,27 @@ function runTest (testName, testObject, testCallback, resultsCallback) {
method.send().on('receipt', function (receipt) { method.send().on('receipt', function (receipt) {
try { try {
let time = Math.ceil((Date.now() - startTime) / 1000.0) let time = Math.ceil((Date.now() - startTime) / 1000.0)
// if (func.type === 'test') {
let topic = Web3.utils.sha3('AssertionEvent(bool,string)') let topic = Web3.utils.sha3('AssertionEvent(bool,string)')
let matchingEvents = []
for (let i in receipt.events) { for (let i in receipt.events) {
let event = receipt.events[i] let event = receipt.events[i]
if (event.raw.topics.indexOf(topic) >= 0) { if (event.raw.topics.indexOf(topic) >= 0) {
matchingEvents.push(web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)) var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)
if (testEvent[0]) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName})
passingNum += 1
} else {
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName})
failureNum += 1
}
} }
} }
return next()
if (matchingEvents.length === 0) {
return next()
}
let result = matchingEvents[0]
if (result[0]) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName})
passingNum += 1
} else {
testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: result[1], context: testName})
failureNum += 1
}
// }
} catch (err) { } catch (err) {
console.log('error!') console.log('error!')
console.dir(err) console.dir(err)
return next(err) return next(err)
} }
next()
}).on('error', function (err) { }).on('error', function (err) {
next(err) next(err)
}) })

Loading…
Cancel
Save