Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
e525eaad
Commit
e525eaad
authored
Feb 01, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abstract test results into callbacks
parent
0c6c94c0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
14 deletions
+31
-14
index.js
index.js
+23
-1
testRunner.js
src/testRunner.js
+8
-13
No files found.
index.js
View file @
e525eaad
...
...
@@ -5,7 +5,29 @@ let Deployer = require('./src/deployer.js');
let
TestRunner
=
require
(
'./src/testRunner.js'
);
var
runTest
=
function
(
contractName
,
contractObj
,
cb
)
{
TestRunner
.
runTest
(
contractName
,
contractObj
,
cb
);
var
testCallback
=
function
(
result
)
{
if
(
result
.
type
===
'contract'
)
{
console
.
log
((
"#"
+
result
.
value
).
green
);
}
else
if
(
result
.
type
===
'testPass'
)
{
console
.
log
(
"
\
t✓ "
.
green
.
bold
+
result
.
value
.
grey
);
}
else
if
(
result
.
type
===
'testFailure'
)
{
console
.
log
(
"
\
t✘ "
.
bold
.
red
+
result
.
value
.
red
);
}
}
var
resultsCallback
=
function
(
err
,
result
)
{
if
(
err
)
{
return
cb
(
err
);
}
if
(
result
.
passingNum
>
0
)
{
console
.
log
((
result
.
passingNum
+
" passing"
).
green
);
}
if
(
result
.
failureNum
>
0
)
{
console
.
log
((
result
.
failureNum
+
" failing"
).
red
);
}
cb
();
}
TestRunner
.
runTest
(
contractName
,
contractObj
,
testCallback
,
resultsCallback
);
}
var
runTestFile
=
function
(
filename
,
web3
)
{
...
...
src/testRunner.js
View file @
e525eaad
...
...
@@ -2,7 +2,7 @@ var async = require('async');
var
changeCase
=
require
(
'change-case'
);
require
(
'colors'
);
function
runTest
(
testName
,
testObject
,
c
allback
)
{
function
runTest
(
testName
,
testObject
,
testCallback
,
resultsC
allback
)
{
let
runList
=
[];
let
specialFunctions
=
[
'beforeAll'
];
let
availableFunctions
=
testObject
.
_jsonInterface
.
filter
((
x
)
=>
x
.
type
===
'function'
).
map
((
x
)
=>
x
.
name
);
...
...
@@ -18,19 +18,16 @@ function runTest(testName, testObject, callback) {
let
passingNum
=
0
,
failureNum
=
0
;
console
.
log
((
"#"
+
testName
).
green
);
testCallback
({
type
:
"contract"
,
value
:
testName
}
);
async
.
eachOfLimit
(
runList
,
1
,
function
(
func
,
index
,
next
)
{
let
method
=
testObject
.
methods
[
func
.
name
].
apply
(
testObject
.
methods
[
func
.
name
],
[]);
if
(
func
.
constant
)
{
method
.
call
().
then
((
result
)
=>
{
if
(
result
)
{
// TODO: should instead be returned in a callback, the caller can
// decide how to handle the output (so works both in console and
// browser)
console
.
log
(
"
\
t✓ "
.
green
.
bold
+
changeCase
.
sentenceCase
(
func
.
name
).
grey
);
testCallback
({
type
:
"testPass"
,
value
:
changeCase
.
sentenceCase
(
func
.
name
)});
passingNum
+=
1
;
}
else
{
console
.
log
(
"
\
t✘ "
.
bold
.
red
+
changeCase
.
sentenceCase
(
func
.
name
).
red
);
testCallback
({
type
:
"testFailure"
,
value
:
changeCase
.
sentenceCase
(
func
.
name
)}
);
failureNum
+=
1
;
}
next
();
...
...
@@ -41,12 +38,10 @@ function runTest(testName, testObject, callback) {
});
}
},
function
()
{
if
(
passingNum
>
0
)
{
console
.
log
((
passingNum
+
" passing"
).
green
);
}
if
(
failureNum
>
0
)
{
console
.
log
((
failureNum
+
" failing"
).
red
);
}
resultsCallback
(
null
,
{
passingNum
:
passingNum
,
failureNum
:
failureNum
});
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment