refactor runTests

pull/7/head
Iuri Matias 7 years ago
parent 0971b1018a
commit 87a7f9fbb0
  1. 22
      src/testRunner.js
  2. 10
      tests/testRunner.js

@ -1,11 +1,19 @@
var async = require('async')
var changeCase = require('change-case')
function runTest (testName, testObject, testCallback, resultsCallback) {
let runList = []
function getAvailableFunctions (jsonInterface) {
return jsonInterface.reverse().filter((x) => x.type === 'function').map((x) => x.name)
}
function getTestFunctions (jsonInterface) {
let specialFunctions = ['beforeAll', 'beforeEach']
let availableFunctions = testObject._jsonInterface.reverse().filter((x) => x.type === 'function').map((x) => x.name)
let testFunctions = testObject._jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function')
return jsonInterface.filter((x) => specialFunctions.indexOf(x.name) < 0 && x.type === 'function')
}
function createRunList (jsonInterface) {
let availableFunctions = getAvailableFunctions(jsonInterface)
let testFunctions = getTestFunctions(jsonInterface)
let runList = []
if (availableFunctions.indexOf('beforeAll') >= 0) {
runList.push({name: 'beforeAll', type: 'internal', constant: false})
@ -18,6 +26,12 @@ function runTest (testName, testObject, testCallback, resultsCallback) {
runList.push({name: func.name, type: 'test', constant: func.constant})
}
return runList
}
function runTest (testName, testObject, testCallback, resultsCallback) {
let runList = createRunList(testObject._jsonInterface)
let passingNum = 0
let failureNum = 0
let timePassed = 0

@ -50,9 +50,9 @@ describe('testRunner', function () {
it('should returns 3 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest' },
{ type: 'testPass', value: 'Initial value should be100' },
{ type: 'testFailure', value: 'Initial value should be200' }
{ type: 'contract', value: 'MyTest' },
{ type: 'testPass', value: 'Initial value should be100', time: 1 },
{ type: 'testFailure', value: 'Initial value should be200', time: 1 }
])
})
})
@ -85,8 +85,8 @@ describe('testRunner', function () {
it('should returns 3 messages', function () {
assert.deepEqual(tests, [
{ type: 'contract', value: 'MyTest' },
{ type: 'testPass', value: 'Initial value should be100' },
{ type: 'testPass', value: 'Initial value should be200' }
{ type: 'testPass', value: 'Initial value should be100', time: 1 },
{ type: 'testPass', value: 'Initial value should be200', time: 1 }
])
})
})

Loading…
Cancel
Save