Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
6dd97c9c
...
6dd97c9cc865464bab4e705fe6824bd8b111312b
authored
2013-03-07 00:53:25 +0100
by
Julien Muetton
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add test results for skipped
1 parent
a228e553
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
19 deletions
modules/tester.js
tests/suites/casper/skip.js
modules/tester.js
View file @
6dd97c9
...
...
@@ -102,8 +102,9 @@ var Tester = function Tester(casper, options) {
this
.
options
=
utils
.
mergeObjects
({
concise
:
false
,
// concise output?
failFast
:
false
,
// terminates a suite as soon as a test fails?
failText
:
"FAIL"
,
// text to use for a succesful test
passText
:
"PASS"
,
// text to use for a failed test
failText
:
"FAIL"
,
// text to use for a failed test
passText
:
"PASS"
,
// text to use for a succesful test
skipText
:
"SKIP"
,
// text to use for a skipped test
pad
:
80
,
// maximum number of chars for a result line
warnText
:
"WARN"
// text to use for a dubious test
},
options
);
...
...
@@ -118,6 +119,12 @@ var Tester = function Tester(casper, options) {
this
.
lastAssertTime
=
timeElapsed
;
});
this
.
on
(
'skipped'
,
function
onSkipped
(
skipped
)
{
var
timeElapsed
=
new
Date
()
-
this
.
currentTestStartTime
;
this
.
currentSuite
.
addSkipped
(
skipped
,
timeElapsed
-
this
.
lastAssertTime
);
this
.
lastAssertTime
=
timeElapsed
;
});
this
.
on
(
'fail'
,
function
onFail
(
failure
)
{
// export
var
valueKeys
=
Object
.
keys
(
failure
.
values
),
...
...
@@ -222,25 +229,28 @@ Tester.prototype.abort = function abort(message) {
};
/**
*
Aborts current test suite
.
*
Skip `nb` tests
.
*
* @param {String} message Warning message (optional)
* @param Integer nb number of tests to skip
* @param String message message to display
*/
Tester
.
prototype
.
skip
=
function
skip
(
n
umber
,
message
)
{
Tester
.
prototype
.
skip
=
function
skip
(
n
b
,
message
)
{
"use strict"
;
var
step
=
this
.
casper
.
step
,
steps
=
this
.
casper
.
steps
,
last
=
steps
.
length
;
if
(
message
)
{
this
.
casper
.
echo
([
this
.
casper
.
colorize
(
'SKIP'
,
'SKIP'
),
'test suite aborted: '
+
message
].
join
(
' '
));
}
this
.
casper
.
step
=
Math
.
min
(
step
+
number
,
last
);
this
.
casper
.
step
=
Math
.
min
(
step
+
nb
,
last
);
this
.
executed
+=
this
.
casper
.
step
-
step
;
return
this
;
return
this
.
processAssertionResult
({
success
:
null
,
standard
:
f
(
"Skipping %d tests"
,
nb
),
message
:
message
,
type
:
"skip"
,
number
:
nb
,
skipped
:
true
});
};
/**
...
...
@@ -1164,7 +1174,11 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
message
=
result
.
message
||
result
.
standard
,
style
=
'INFO'
,
status
=
this
.
options
.
passText
;
if
(
!
result
.
success
)
{
if
(
null
===
result
.
success
)
{
eventName
=
'skipped'
;
style
=
'SKIP'
;
status
=
this
.
options
.
skipText
;
}
else
if
(
!
result
.
success
)
{
eventName
=
'fail'
;
style
=
'RED_BAR'
;
status
=
this
.
options
.
failText
;
...
...
@@ -1254,6 +1268,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
save
=
save
||
this
.
options
.
save
;
var
failed
=
this
.
suiteResults
.
countFailed
(),
passed
=
this
.
suiteResults
.
countPassed
(),
skipped
=
this
.
suiteResults
.
countSkipped
(),
total
=
this
.
suiteResults
.
countTotal
(),
statusText
,
style
,
...
...
@@ -1267,16 +1282,20 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
if
(
failed
>
0
)
{
statusText
=
this
.
options
.
failText
;
style
=
'RED_BAR'
;
}
else
if
(
skipped
>
0
)
{
statusText
=
this
.
options
.
skipText
;
style
=
'SKIP_BAR'
;
}
else
{
statusText
=
this
.
options
.
passText
;
style
=
'GREEN_BAR'
;
}
result
=
f
(
'%s %s tests executed in %ss, %d passed, %d failed.'
,
result
=
f
(
'%s %s tests executed in %ss, %d passed, %d failed
, %d skipped
.'
,
statusText
,
total
,
utils
.
ms2seconds
(
this
.
suiteResults
.
calculateDuration
()),
passed
,
failed
);
failed
,
skipped
);
}
this
.
casper
.
echo
(
result
,
style
,
this
.
options
.
pad
);
if
(
failed
>
0
)
{
...
...
@@ -1483,6 +1502,20 @@ TestSuiteResult.prototype.countPassed = function countPassed() {
};
/**
* Returns the number of skipped tests.
*
* @return Number
*/
TestSuiteResult
.
prototype
.
countSkipped
=
function
countSkipped
()
{
"use strict"
;
return
this
.
map
(
function
(
result
)
{
return
result
.
skipped
;
}).
reduce
(
function
(
a
,
b
)
{
return
a
+
b
;
},
0
);
};
/**
* Returns the number of warnings.
*
* @return Number
...
...
@@ -1507,6 +1540,16 @@ TestSuiteResult.prototype.isFailed = function isFailed() {
};
/**
* Checks if the suite has skipped tests.
*
* @return Number
*/
TestSuiteResult
.
prototype
.
isSkipped
=
function
isFailed
()
{
"use strict"
;
return
this
.
countSkipped
()
>
0
;
};
/**
* Returns all failures from this suite.
*
* @return Array
...
...
@@ -1535,6 +1578,20 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() {
};
/**
* Returns all skipped tests from this suite.
*
* @return Array
*/
TestSuiteResult
.
prototype
.
getAllSkipped
=
function
getAllSkipped
()
{
"use strict"
;
var
skipped
=
[];
this
.
forEach
(
function
(
result
)
{
skipped
=
skipped
.
concat
(
result
.
skipped
);
});
return
skipped
;
};
/**
* Returns all results from this suite.
*
* @return Array
...
...
@@ -1572,6 +1629,7 @@ function TestCaseResult(options) {
this
.
errors
=
[];
this
.
failures
=
[];
this
.
passes
=
[];
this
.
skip
=
[];
this
.
warnings
=
[];
this
.
config
=
options
&&
options
.
config
;
this
.
__defineGetter__
(
"assertions"
,
function
()
{
...
...
@@ -1586,6 +1644,9 @@ function TestCaseResult(options) {
this
.
__defineGetter__
(
"passed"
,
function
()
{
return
this
.
passes
.
length
;
});
this
.
__defineGetter__
(
"skipped"
,
function
()
{
return
this
.
skip
.
length
;
});
}
exports
.
TestCaseResult
=
TestCaseResult
;
...
...
@@ -1627,6 +1688,20 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) {
};
/**
* Adds a success record and its execution time.
*
* @param Object success
* @param Number time
*/
TestCaseResult
.
prototype
.
addSkipped
=
function
addSkipped
(
skipped
,
time
)
{
"use strict"
;
skipped
.
suite
=
this
.
name
;
skipped
.
time
=
time
;
this
.
skip
.
push
(
skipped
);
};
/**
* Adds a warning record.
*
* @param Object warning
...
...
tests/suites/casper/skip.js
View file @
6dd97c9
/*global casper*/
/*jshint strict:false*/
casper
.
test
.
begin
(
'Skip tests'
,
1
,
function
(
test
)
{
casper
.
test
.
begin
(
'Skip tests'
,
2
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
);
casper
.
...
...
@@ -19,7 +19,7 @@ casper.test.begin('Skip tests', 1, function(test) {
});
});
casper
.
test
.
begin
(
'Skip multiple'
,
1
,
function
(
test
)
{
casper
.
test
.
begin
(
'Skip multiple'
,
3
,
function
(
test
)
{
casper
.
then
(
function
()
{
test
.
skip
(
2
);
...
...
@@ -50,7 +50,7 @@ casper.test.begin('Skip more than there is', 0, function(test) {
});
});
casper
.
test
.
begin
(
'
Next suite should be executed
'
,
1
,
function
(
test
)
{
casper
.
test
.
begin
(
'
Skip does not polluate next suite
'
,
1
,
function
(
test
)
{
casper
.
then
(
function
()
{
test
.
pass
(
"This test should be executed."
);
...
...
Please
register
or
sign in
to post a comment