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
c3ff7b08
...
c3ff7b085fe0e6837c0a9afe655a7c163aa149b6
authored
2013-03-10 22:24:00 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactored Tester#skip
1 parent
caf73290
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
72 deletions
modules/casper.js
modules/tester.js
tests/clitests/runtests.py
tests/suites/tester/skip.js
modules/casper.js
View file @
c3ff7b0
...
...
@@ -1626,6 +1626,7 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) {
* @param Integer nb Number of steps to bypass
*/
Casper
.
prototype
.
thenBypass
=
function
thenBypass
(
nb
)
{
"use strict"
;
return
this
.
then
(
function
_thenBypass
()
{
this
.
bypass
(
nb
);
});
...
...
@@ -1638,6 +1639,7 @@ Casper.prototype.thenBypass = function thenBypass(nb) {
* @param Integer nb Number of steps to bypass
*/
Casper
.
prototype
.
thenBypassIf
=
function
thenBypassIf
(
condition
,
nb
)
{
"use strict"
;
return
this
.
then
(
function
_thenBypassIf
()
{
if
(
utils
.
isFunction
(
condition
))
{
condition
=
condition
.
call
(
this
);
...
...
@@ -1655,6 +1657,7 @@ Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) {
* @param Integer nb Number of tests to bypass
*/
Casper
.
prototype
.
thenBypassUnless
=
function
thenBypassUnless
(
condition
,
nb
)
{
"use strict"
;
return
this
.
then
(
function
_thenBypassUnless
()
{
if
(
utils
.
isFunction
(
condition
))
{
condition
=
condition
.
call
(
this
);
...
...
modules/tester.js
View file @
c3ff7b0
...
...
@@ -130,7 +130,7 @@ var Tester = function Tester(casper, options) {
this
.
on
(
'skipped'
,
function
onSkipped
(
skipped
)
{
var
timeElapsed
=
new
Date
()
-
this
.
currentTestStartTime
;
this
.
currentSuite
.
addSkip
ped
(
skipped
,
timeElapsed
-
this
.
lastAssertTime
);
this
.
currentSuite
.
addSkip
(
skipped
,
timeElapsed
-
this
.
lastAssertTime
);
this
.
lastAssertTime
=
timeElapsed
;
});
...
...
@@ -226,7 +226,7 @@ exports.Tester = Tester;
/**
* Aborts current test suite.
*
* @param
{String}
message Warning message (optional)
* @param
String
message Warning message (optional)
*/
Tester
.
prototype
.
abort
=
function
abort
(
message
)
{
"use strict"
;
...
...
@@ -238,13 +238,13 @@ Tester.prototype.abort = function abort(message) {
*
* @param Integer nb Number of tests to skip
* @param String message Message to display
* @return Object
*/
Tester
.
prototype
.
skip
=
function
skip
(
nb
,
message
)
{
"use strict"
;
this
.
casper
.
bypass
(
nb
);
return
this
.
processAssertionResult
({
success
:
null
,
standard
:
f
(
"
Skipping %d tests"
,
nb
),
standard
:
f
(
"
%d test%s skipped"
,
nb
,
nb
>
1
?
"s"
:
""
),
message
:
message
,
type
:
"skip"
,
number
:
nb
,
...
...
@@ -938,7 +938,11 @@ Tester.prototype.begin = function begin() {
/**
* Render a colorized output. Basically a proxy method for
* Casper.Colorizer#colorize()
* `Casper.Colorizer#colorize()`.
*
* @param String message
* @param String style The style name
* @return String
*/
Tester
.
prototype
.
colorize
=
function
colorize
(
message
,
style
)
{
"use strict"
;
...
...
@@ -974,7 +978,8 @@ Tester.prototype.done = function done() {
this
.
processError
(
error
);
}
}
if
(
this
.
currentSuite
&&
this
.
currentSuite
.
planned
&&
this
.
currentSuite
.
planned
!==
this
.
executed
)
{
if
(
this
.
currentSuite
&&
this
.
currentSuite
.
planned
&&
this
.
currentSuite
.
planned
!==
this
.
executed
+
this
.
currentSuite
.
skipped
)
{
this
.
dubious
(
this
.
currentSuite
.
planned
,
this
.
executed
,
this
.
currentSuite
.
name
);
}
else
if
(
planned
&&
planned
!==
this
.
executed
)
{
// BC
...
...
@@ -1193,7 +1198,7 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
/**
* Processes an error.
*
* @param
{Error}
error
* @param
Error
error
*/
Tester
.
prototype
.
processError
=
function
processError
(
error
)
{
"use strict"
;
...
...
@@ -1209,8 +1214,8 @@ Tester.prototype.processError = function processError(error) {
/**
* Processes a PhantomJS error, which is an error message and a backtrace.
*
* @param
{String}
message
* @param
{Array}
backtrace
* @param
String
message
* @param
Array
backtrace
*/
Tester
.
prototype
.
processPhantomError
=
function
processPhantomError
(
msg
,
backtrace
)
{
"use strict"
;
...
...
@@ -1265,13 +1270,10 @@ Tester.prototype.renderFailureDetails = function renderFailureDetails() {
*/
Tester
.
prototype
.
renderResults
=
function
renderResults
(
exit
,
status
,
save
)
{
"use strict"
;
/*jshint maxstatements:2
5
*/
/*jshint maxstatements:2
0
*/
save
=
save
||
this
.
options
.
save
;
var
dubious
=
this
.
suiteResults
.
countDubious
(),
failed
=
this
.
suiteResults
.
countFailed
(),
passed
=
this
.
suiteResults
.
countPassed
(),
var
failed
=
this
.
suiteResults
.
countFailed
(),
total
=
this
.
suiteResults
.
countExecuted
(),
skipped
=
this
.
suiteResults
.
countSkipped
(),
statusText
,
style
,
result
,
...
...
@@ -1292,10 +1294,10 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
statusText
,
total
,
utils
.
ms2seconds
(
this
.
suiteResults
.
calculateDuration
()),
passed
,
this
.
suiteResults
.
countPassed
()
,
failed
,
dubious
,
skipped
);
this
.
suiteResults
.
countDubious
()
,
this
.
suiteResults
.
countSkipped
()
);
}
this
.
casper
.
echo
(
result
,
style
,
this
.
options
.
pad
);
if
(
failed
>
0
)
{
...
...
@@ -1606,7 +1608,7 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() {
*
* @return Array
*/
TestSuiteResult
.
prototype
.
getAllSkip
ped
=
function
getAllSkipped
()
{
TestSuiteResult
.
prototype
.
getAllSkip
s
=
function
getAllSkips
()
{
"use strict"
;
var
skipped
=
[];
this
.
forEach
(
function
(
result
)
{
...
...
@@ -1653,7 +1655,7 @@ function TestCaseResult(options) {
this
.
errors
=
[];
this
.
failures
=
[];
this
.
passes
=
[];
this
.
skip
=
[];
this
.
skip
s
=
[];
this
.
warnings
=
[];
this
.
config
=
options
&&
options
.
config
;
this
.
__defineGetter__
(
"assertions"
,
function
()
{
...
...
@@ -1674,7 +1676,11 @@ function TestCaseResult(options) {
return
this
.
passes
.
length
;
});
this
.
__defineGetter__
(
"skipped"
,
function
()
{
return
this
.
skip
.
length
;
return
this
.
skips
.
map
(
function
(
skip
)
{
return
skip
.
number
;
}).
reduce
(
function
(
a
,
b
)
{
return
a
+
b
;
},
0
);
});
}
exports
.
TestCaseResult
=
TestCaseResult
;
...
...
@@ -1722,11 +1728,11 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) {
* @param Object success
* @param Number time
*/
TestCaseResult
.
prototype
.
addSkip
ped
=
function
addSkipped
(
skipped
,
time
)
{
TestCaseResult
.
prototype
.
addSkip
=
function
addSkip
(
skipped
,
time
)
{
"use strict"
;
skipped
.
suite
=
this
.
name
;
skipped
.
time
=
time
;
this
.
skip
.
push
(
skipped
);
this
.
skip
s
.
push
(
skipped
);
};
...
...
tests/clitests/runtests.py
View file @
c3ff7b0
...
...
@@ -134,7 +134,7 @@ class CasperExecTest(unittest.TestCase):
'# subject: false'
,
'FAIL 1 tests executed'
,
'0 passed'
,
'1 failed
.
'
,
'1 failed'
,
],
failing
=
True
)
@timeout
(
60
)
...
...
tests/suites/tester/skip.js
View file @
c3ff7b0
/*global casper*/
/*jshint strict:false*/
casper
.
test
.
begin
(
'Skip tests'
,
1
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
);
casper
.
then
(
function
()
{
test
.
skip
(
1
);
}).
then
(
function
()
{
test
.
fail
(
"This test should be skipped."
);
}).
then
(
function
()
{
test
.
pass
(
"This test should be executed."
);
});
casper
.
run
(
function
()
{
casper
.
test
.
begin
(
'Skip tests'
,
4
,
function
(
test
)
{
test
.
assert
(
true
,
'First test executed'
);
test
.
assert
(
true
,
'Second test executed'
);
test
.
skip
(
2
,
'Two tests skipped'
);
test
.
done
();
});
});
casper
.
test
.
begin
(
'Skip multiple'
,
1
,
function
(
test
)
{
casper
.
then
(
function
()
{
test
.
skip
(
2
);
}).
then
(
function
()
{
test
.
fail
(
"This test should be skipped."
);
}).
then
(
function
()
{
test
.
fail
(
"This test should be skipped."
);
}).
then
(
function
()
{
test
.
pass
(
"This test should be executed."
);
});
casper
.
run
(
function
()
{
casper
.
test
.
begin
(
'Skip tests after'
,
4
,
function
(
test
)
{
test
.
skip
(
2
,
'Two tests skipped'
);
test
.
assert
(
true
,
'Third test executed'
);
test
.
assert
(
true
,
'Fourth test executed'
);
test
.
done
();
});
});
casper
.
test
.
begin
(
'Skip more than there is'
,
0
,
function
(
test
)
{
casper
.
then
(
function
()
{
test
.
skip
(
2
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
casper
.
test
.
begin
(
'Skip does not polluate next suite'
,
1
,
function
(
test
)
{
casper
.
then
(
function
()
{
test
.
pass
(
"This test should be executed."
);
});
casper
.
run
(
function
()
{
casper
.
test
.
begin
(
'Skip tests (asynchronous)'
,
1
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
,
function
()
{
test
.
skip
(
1
);
}).
run
(
function
()
{
test
.
done
();
});
});
...
...
Please
register
or
sign in
to post a comment