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
6baa46ce
...
6baa46ce8fd47a4fc18ab37b34b3013f16463ed4
authored
2012-01-05 00:37:09 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added events.filter and events.onfilter methods
1 parent
aea6e574
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
13 deletions
modules/casper.js
modules/events.js
tests/run.js
modules/casper.js
View file @
6baa46c
...
...
@@ -653,7 +653,7 @@ Casper.prototype.open = function(location, options) {
this
.
setHttpAuth
(
httpAuth
.
username
,
httpAuth
.
password
);
}
this
.
emit
(
'open'
,
location
);
this
.
page
.
open
(
location
);
this
.
page
.
open
(
this
.
filter
(
'open.location'
,
location
)
||
location
);
return
this
;
};
...
...
modules/events.js
View file @
6baa46c
...
...
@@ -213,3 +213,29 @@ EventEmitter.prototype.listeners = function(type) {
}
return
this
.
_events
[
type
];
};
// Added for CasperJS: filters a value attached to an event
EventEmitter
.
prototype
.
filter
=
function
()
{
var
type
=
arguments
[
0
];
if
(
!
this
.
_filters
)
{
return
;
}
var
filter
=
this
.
_filters
[
type
];
if
(
!
filter
||
typeof
filter
!==
'function'
)
{
return
;
}
return
filter
.
apply
(
null
,
Array
.
prototype
.
splice
.
call
(
arguments
,
1
));
};
EventEmitter
.
prototype
.
setFilter
=
function
(
type
,
filterFn
)
{
if
(
!
this
.
_filters
)
this
.
_filters
=
{};
if
(
'function'
!==
typeof
filterFn
)
{
throw
new
Error
(
'setFilter only takes instances of Function'
);
}
if
(
!
this
.
_filters
[
type
])
{
this
.
_filters
[
type
]
=
filterFn
;
return
true
;
}
// TODO: process multiple filters? in which order? disallow?
return
false
;
};
...
...
tests/run.js
View file @
6baa46c
...
...
@@ -5,28 +5,23 @@ if (!phantom.casperLoaded) {
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
// Overriding Casper.open to prefix all test urls
require
(
'casper'
).
Casper
.
extend
({
open
:
function
(
location
,
options
)
{
options
=
utils
.
isType
(
options
,
"object"
)
?
options
:
{};
this
.
requestUrl
=
location
;
var
url
=
'file://'
+
phantom
.
casperPath
+
'/'
+
location
;
this
.
page
.
open
(
url
);
return
this
;
}
});
var
casper
=
require
(
'casper'
).
create
({
faultTolerant
:
false
});
// Overriding Casper.open to prefix all test urls
casper
.
setFilter
(
'open.location'
,
function
(
location
)
{
return
'file://'
+
phantom
.
casperPath
+
'/'
+
location
;
});
var
tests
=
[];
if
(
casper
.
cli
.
args
.
length
)
{
tests
=
casper
.
cli
.
args
.
filter
(
function
(
path
)
{
return
fs
.
isFile
(
path
)
||
fs
.
isDirectory
(
path
);
});
}
if
(
!
tests
.
length
)
{
if
(
casper
.
cli
.
args
.
length
>
0
)
{
casper
.
echo
(
'No valid test path passed, exiting.'
,
'ERROR'
).
exit
(
1
);
...
...
@@ -35,4 +30,5 @@ if (!tests.length) {
casper
.
echo
(
'Running complete CasperJS test suite'
,
'INFO'
);
tests
=
[
fs
.
absolute
(
fs
.
pathJoin
(
phantom
.
casperPath
,
'tests'
,
'suites'
))];
}
casper
.
test
.
runSuites
.
apply
(
casper
.
test
,
tests
);
...
...
Please
register
or
sign in
to post a comment