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
05250d2e
...
05250d2edcd9d6e7107d52fbea8de4bc28bf9c4b
authored
2013-06-02 22:48:25 +0200
by
Laurent Jouanneau
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
refs #482: sync with master
2 parents
c1946343
e664bdd4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
7 deletions
bin/bootstrap.js
modules/casper.js
modules/colorizer.js
samples/googlematch.js
tests/suites/casper/evaluate.js
bin/bootstrap.js
View file @
05250d2
...
...
@@ -28,11 +28,17 @@
*
*/
/*global console, phantom, require:true*/
/*global
process,
console, phantom, require:true*/
/*jshint maxstatements:33, maxcomplexity:10*/
// node check
if
(
'process'
in
this
&&
process
.
title
===
"node"
)
{
console
.
error
(
'CasperJS cannot be executed within a nodejs environment'
);
process
.
exit
(
1
);
}
// phantom check
if
(
!
phantom
)
{
if
(
!
(
'phantom'
in
this
)
)
{
console
.
error
(
'CasperJS needs to be executed in a PhantomJS environment http://phantomjs.org/'
);
}
...
...
modules/casper.js
View file @
05250d2
...
...
@@ -667,7 +667,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
this
.
injectClientUtils
();
// function context
if
(
arguments
.
length
===
1
)
{
return
this
.
page
.
evaluate
(
fn
);
return
utils
.
clone
(
this
.
page
.
evaluate
(
fn
)
);
}
else
if
(
arguments
.
length
===
2
)
{
// check for closure signature if it matches context
if
(
utils
.
isObject
(
context
)
&&
eval
(
fn
).
length
===
Object
.
keys
(
context
).
length
)
{
...
...
@@ -679,7 +679,7 @@ Casper.prototype.evaluate = function evaluate(fn, context) {
// phantomjs-style signature
context
=
[].
slice
.
call
(
arguments
).
slice
(
1
);
}
return
this
.
page
.
evaluate
.
apply
(
this
.
page
,
[
fn
].
concat
(
context
));
return
utils
.
clone
(
this
.
page
.
evaluate
.
apply
(
this
.
page
,
[
fn
].
concat
(
context
)
));
};
/**
...
...
modules/colorizer.js
View file @
05250d2
...
...
@@ -33,6 +33,7 @@
var
require
=
patchRequire
(
require
);
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
var
env
=
require
(
'system'
).
env
;
exports
.
create
=
function
create
(
type
)
{
"use strict"
;
...
...
@@ -79,7 +80,7 @@ var Colorizer = function Colorizer() {
* @return String
*/
this
.
colorize
=
function
colorize
(
text
,
styleName
,
pad
)
{
if
(
fs
.
isWindows
(
)
||
!
(
styleName
in
styles
))
{
if
(
(
fs
.
isWindows
()
&&
!
env
[
'ANSICON'
]
)
||
!
(
styleName
in
styles
))
{
return
text
;
}
return
this
.
format
(
text
,
styles
[
styleName
],
pad
);
...
...
@@ -93,7 +94,7 @@ var Colorizer = function Colorizer() {
* @return String
*/
this
.
format
=
function
format
(
text
,
style
,
pad
)
{
if
(
fs
.
isWindows
(
)
||
!
utils
.
isObject
(
style
))
{
if
(
(
fs
.
isWindows
()
&&
!
env
[
'ANSICON'
]
)
||
!
utils
.
isObject
(
style
))
{
return
text
;
}
var
codes
=
[];
...
...
samples/googlematch.js
View file @
05250d2
...
...
@@ -40,7 +40,7 @@ casper.echo("Let the match begin between \"" + (terms.join('", "')) + "\"!");
casper
.
start
(
"http://google.fr/"
);
casper
.
each
(
terms
,
function
(
casper
,
term
,
i
)
{
this
.
echo
(
'Fe
ct
hing score for '
+
term
);
this
.
echo
(
'Fe
tc
hing score for '
+
term
);
this
.
then
(
function
()
{
this
.
fill
(
'form[action="/search"]'
,
{
q
:
term
},
true
);
});
...
...
tests/suites/casper/evaluate.js
View file @
05250d2
...
...
@@ -90,3 +90,23 @@ casper.test.begin('thenEvaluate() tests', 2, function(test) {
test
.
done
();
});
});
// https://github.com/n1k0/casperjs/issues/489
// https://groups.google.com/forum/?fromgroups=#!topic/casperjs/95IgDMFnEKM
casper
.
test
.
begin
(
"evaluate() returns a value which can be altered"
,
1
,
function
(
test
)
{
var
list
;
casper
.
start
().
then
(
function
()
{
list
=
this
.
evaluate
(
function
()
{
return
[{
a
:
1
},
{
b
:
2
}];
});
var
first
=
list
[
0
];
first
.
a
=
42
;
test
.
assertEquals
(
list
,
[{
a
:
42
},
{
b
:
2
}],
'evaluate() returns a cloned value which can be altered'
);
});
casper
.
run
(
function
()
{
test
.
done
();
});
});
...
...
Please
register
or
sign in
to post a comment