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
df4a9c2f
...
df4a9c2f88e77a5026563db3f9b46bfa6fecbb70
authored
2013-01-08 12:54:06 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
closes #346 - emit a warning when trying to use casper.test in non-test env
1 parent
ab1ee319
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
modules/casper.js
modules/tester.js
modules/casper.js
View file @
df4a9c2
...
...
@@ -154,18 +154,30 @@ var Casper = function Casper(options) {
this
.
started
=
false
;
this
.
step
=
-
1
;
this
.
steps
=
[];
if
(
phantom
.
casperTest
)
{
this
.
test
=
tester
.
create
(
this
);
}
this
.
_test
=
undefined
;
this
.
__defineGetter__
(
'test'
,
function
()
{
if
(
!
phantom
.
casperTest
)
{
this
.
emit
(
'tester.called'
);
return
;
}
if
(
!
utils
.
isObject
(
this
.
_test
))
{
this
.
_test
=
tester
.
create
(
this
);
}
return
this
.
_test
;
});
this
.
once
(
'tester.called'
,
function
()
{
this
.
warn
(
'please use `casperjs test` command'
);
});
// init phantomjs error handler
this
.
initErrorHandler
();
this
.
on
(
'error'
,
function
(
msg
,
backtrace
)
{
if
(
msg
===
this
.
test
.
SKIP_MESSAGE
)
{
// FIXME: decouple testing
if
(
msg
===
'__termination__'
)
{
return
;
}
if
(
msg
.
indexOf
(
'AssertionError'
)
===
0
)
{
// FIXME: decouple testing
if
(
msg
.
indexOf
(
'AssertionError'
)
===
0
)
{
return
;
}
var
c
=
this
.
getColorizer
();
...
...
@@ -1313,10 +1325,10 @@ Casper.prototype.runStep = function runStep(step) {
var
skipLog
=
utils
.
isObject
(
step
.
options
)
&&
step
.
options
.
skipLog
===
true
,
stepInfo
=
f
(
"Step %d/%d"
,
this
.
step
,
this
.
steps
.
length
),
stepResult
;
function
getCurrentSuite
Num
(
casper
)
{
if
(
casper
.
test
)
{
return
casper
.
test
.
currentSuiteNum
+
"-"
+
casper
.
step
;
}
else
{
function
getCurrentSuite
Id
(
casper
)
{
try
{
return
casper
.
test
.
getCurrentSuiteId
()
;
}
catch
(
e
)
{
return
casper
.
step
;
}
}
...
...
@@ -1326,7 +1338,7 @@ Casper.prototype.runStep = function runStep(step) {
if
(
utils
.
isNumber
(
this
.
options
.
stepTimeout
)
&&
this
.
options
.
stepTimeout
>
0
)
{
var
stepTimeoutCheckInterval
=
setInterval
(
function
_check
(
self
,
start
,
stepNum
)
{
if
(
new
Date
().
getTime
()
-
start
>
self
.
options
.
stepTimeout
)
{
if
(
getCurrentSuite
Num
(
self
)
===
stepNum
)
{
if
(
getCurrentSuite
Id
(
self
)
===
stepNum
)
{
self
.
emit
(
'step.timeout'
);
if
(
utils
.
isFunction
(
self
.
options
.
onStepTimeout
))
{
self
.
options
.
onStepTimeout
.
call
(
self
,
self
.
options
.
stepTimeout
,
stepNum
);
...
...
@@ -1334,7 +1346,7 @@ Casper.prototype.runStep = function runStep(step) {
}
clearInterval
(
stepTimeoutCheckInterval
);
}
},
this
.
options
.
stepTimeout
,
this
,
new
Date
().
getTime
(),
getCurrentSuite
Num
(
this
));
},
this
.
options
.
stepTimeout
,
this
,
new
Date
().
getTime
(),
getCurrentSuite
Id
(
this
));
}
this
.
emit
(
'step.start'
,
step
);
try
{
...
...
modules/tester.js
View file @
df4a9c2
...
...
@@ -987,6 +987,16 @@ Tester.prototype.findTestFiles = function findTestFiles(dir) {
};
/**
* Computes current suite identifier.
*
* @return String
*/
Tester
.
prototype
.
getCurrentSuiteId
=
function
getCurrentSuiteId
()
{
"use strict"
;
return
casper
.
test
.
currentSuiteNum
+
"-"
+
casper
.
step
;
};
/**
* Formats a message to highlight some parts of it.
*
* @param String message
...
...
Please
register
or
sign in
to post a comment