fix to avoiding duplicate passing or failing tests due to multiple asserts

pull/7/head
Iuri Matias 7 years ago
parent 830683fb3c
commit 1ff535a194
  1. 15
      src/testRunner.js

@ -61,19 +61,26 @@ function runTest (testName, testObject, testCallback, resultsCallback) {
let time = Math.ceil((Date.now() - startTime) / 1000.0) let time = Math.ceil((Date.now() - startTime) / 1000.0)
let topic = Web3.utils.sha3('AssertionEvent(bool,string)') let topic = Web3.utils.sha3('AssertionEvent(bool,string)')
let testPassed = false
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) {
var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data) var testEvent = web3.eth.abi.decodeParameters(['bool', 'string'], event.raw.data)
if (testEvent[0]) { 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}) testCallback({type: 'testFailure', value: changeCase.sentenceCase(func.name), time: time, errMsg: testEvent[1], context: testName})
failureNum += 1 failureNum += 1
return next()
} }
testPassed = true
} }
} }
if (testPassed) {
testCallback({type: 'testPass', value: changeCase.sentenceCase(func.name), time: time, context: testName})
passingNum += 1
}
return next() return next()
} catch (err) { } catch (err) {
console.log('error!') console.log('error!')

Loading…
Cancel
Save