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
f818855f
...
f818855f70264557a26411b4131db0d0d2e054dd
authored
2012-05-25 08:33:01 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
work in progress
1 parent
f8d75e2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
36 deletions
modules/tester.js
tests/suites/tester.js
modules/tester.js
View file @
f818855
...
...
@@ -76,16 +76,25 @@ var Tester = function Tester(casper, options) {
});
this
.
on
(
'fail'
,
function
onFail
(
failure
)
{
// export
this
.
exporter
.
addFailure
(
fs
.
absolute
(
failure
.
file
),
failure
.
message
,
failure
.
details
||
"test failed"
,
failure
.
type
||
"unknown"
);
this
.
testResults
.
failures
.
push
(
failure
);
// special printing
switch
(
failure
.
type
)
{
case
'assertEquals'
:
this
.
comment
(
' got: '
+
utils
.
serialize
(
failure
.
values
.
subject
));
this
.
comment
(
' expected: '
+
utils
.
serialize
(
failure
.
values
.
expected
));
break
;
}
});
// methods
/**
* Asserts that a condition strictly resolves to true.
*
* @param Boolean subject
* @param String message Test description
* @param Boolean subject
* @param String message Test description
* @param Object|null context Assertion context object
*/
this
.
assert
=
this
.
assertTrue
=
function
assert
(
subject
,
message
,
context
)
{
this
.
processAssertionResult
(
utils
.
mergeObjects
({
...
...
@@ -103,34 +112,23 @@ var Tester = function Tester(casper, options) {
/**
* Asserts that two values are strictly equals.
*
* @param Mixed subject The value to test
* @param Mixed expected The expected value
* @param String message Test description
* @param Mixed subject The value to test
* @param Mixed expected The expected value
* @param String message Test description
* @param Object|null context Assertion context object
*/
this
.
assertEquals
=
this
.
assertEqual
=
function
assertEquals
(
subject
,
expected
,
message
)
{
var
eventName
;
message
=
message
||
""
;
if
(
this
.
testEquals
(
subject
,
expected
))
{
eventName
=
"success"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
passText
,
'INFO'
)
+
' '
+
this
.
formatMessage
(
message
));
this
.
testResults
.
passed
++
;
}
else
{
eventName
=
"fail"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
failText
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
' got: '
+
utils
.
serialize
(
subject
));
this
.
comment
(
' expected: '
+
utils
.
serialize
(
expected
));
this
.
testResults
.
failed
++
;
}
this
.
emit
(
eventName
,
{
type
:
"assertEquals"
,
message
:
message
,
this
.
assertEquals
=
this
.
assertEqual
=
function
assertEquals
(
subject
,
expected
,
message
,
context
)
{
this
.
processAssertionResult
(
utils
.
mergeObjects
({
success
:
this
.
testEquals
(
subject
,
expected
),
type
:
"assertEquals"
,
details
:
f
(
"test failed; expected: %s; got: %s"
,
expected
,
subject
),
message
:
message
,
file
:
this
.
currentTestFile
,
values
:
{
subject
:
subject
,
expected
:
expected
}
});
}
,
context
||
{})
);
};
/**
...
...
@@ -169,22 +167,22 @@ var Tester = function Tester(casper, options) {
/**
* Asserts that a code evaluation in remote DOM resolves to true.
*
* @param Function fn
A function to be evaluated in remote DOM
* @param String message
Test description
* @param Object
context
Object containing the parameters to inject into the function (optional)
* @param Function fn A function to be evaluated in remote DOM
* @param String message Test description
* @param Object
params
Object containing the parameters to inject into the function (optional)
*/
this
.
assertEval
=
function
assertEval
(
fn
,
message
,
context
)
{
return
this
.
assert
(
casper
.
evaluate
(
fn
,
context
),
message
);
this
.
assertEval
=
function
assertEval
(
fn
,
message
,
params
,
context
)
{
return
this
.
assert
(
casper
.
evaluate
(
fn
,
params
),
message
,
context
);
};
/**
* Asserts that the result of a code evaluation in remote DOM equals
* an expected value.
*
* @param Function
fn
The function to be evaluated in remote DOM
* @param Boolean
expected
The expected value
* @param String
message
Test description
* @param Object
context
Object containing the parameters to inject into the function (optional)
* @param Function
fn
The function to be evaluated in remote DOM
* @param Boolean
expected
The expected value
* @param String
message
Test description
* @param Object
params
Object containing the parameters to inject into the function (optional)
*/
this
.
assertEvalEquals
=
this
.
assertEvalEqual
=
function
assertEvalEquals
(
fn
,
expected
,
message
,
context
)
{
return
this
.
assertEquals
(
casper
.
evaluate
(
fn
,
context
),
expected
,
message
);
...
...
@@ -414,7 +412,13 @@ var Tester = function Tester(casper, options) {
* @param String message
*/
this
.
fail
=
function
fail
(
message
,
context
)
{
this
.
assert
(
false
,
message
,
context
);
this
.
processAssertionResult
(
utils
.
mergeObjects
({
success
:
false
,
type
:
"fail"
,
details
:
"explicit call to fail()"
,
message
:
message
,
file
:
this
.
currentTestFile
},
context
||
{}));
};
/**
...
...
@@ -470,8 +474,14 @@ var Tester = function Tester(casper, options) {
*
* @param String message
*/
this
.
pass
=
function
pass
(
message
)
{
this
.
assert
(
true
,
message
);
this
.
pass
=
function
pass
(
message
,
context
)
{
this
.
processAssertionResult
(
utils
.
mergeObjects
({
success
:
true
,
type
:
"pass"
,
details
:
"explicit call to pass()"
,
message
:
message
,
file
:
this
.
currentTestFile
},
context
||
{}));
};
/**
...
...
tests/suites/tester.js
View file @
f818855
...
...
@@ -42,7 +42,7 @@ var expected = [
].
map
(
function
(
entry
)
{
return
fs
.
pathJoin
.
apply
(
fs
,
[
testDirRoot
].
concat
(
entry
.
split
(
'/'
)));
});
t
.
assertEquals
(
files
,
expected
,
'findTestFiles() find test files and sort them'
);
t
.
assertEquals
(
files
,
[]
,
'findTestFiles() find test files and sort them'
);
t
.
comment
(
'Tester.assertTextExists()'
);
casper
.
start
(
'tests/site/index.html'
,
function
()
{
...
...
Please
register
or
sign in
to post a comment