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
583d1e7b
...
583d1e7b33e2a62b6aa1a44f9ea7865f49458155
authored
2013-03-10 15:30:25 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
better error handling
1 parent
82863faf
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
5 deletions
.jshintignore
bin/bootstrap.js
modules/casper.js
modules/tester.js
tests/clitests/error/syntax.js
tests/clitests/runtests.py
.jshintignore
View file @
583d1e7
...
...
@@ -5,3 +5,4 @@ modules/querystring.js
samples/**
tests/**
tmp
./*.js
...
...
bin/bootstrap.js
View file @
583d1e7
...
...
@@ -69,12 +69,16 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
}
function
__die
(
message
)
{
if
(
message
)
{
console
.
error
(
message
);
}
phantom
.
exit
(
1
);
}
function
__terminate
(
message
)
{
if
(
message
)
{
console
.
log
(
message
);
}
phantom
.
exit
();
}
...
...
@@ -90,13 +94,17 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
}
})(
phantom
.
version
);
// Hooks in default phantomjs error handler to print a hint when a possible
// casperjs command misuse is detected.
// Hooks in default phantomjs error handler
phantom
.
onError
=
function
onPhantomError
(
msg
,
trace
)
{
phantom
.
defaultErrorHandler
.
apply
(
phantom
,
arguments
);
// print a hint when a possible casperjs command misuse is detected
if
(
msg
.
indexOf
(
"ReferenceError: Can't find variable: casper"
)
===
0
)
{
console
.
error
(
'Hint: you may want to use the `casperjs test` command.'
);
}
// exits on syntax error
if
(
msg
.
indexOf
(
'SyntaxError: Parse error'
)
===
0
)
{
__die
();
}
};
// Patching fs
...
...
modules/casper.js
View file @
583d1e7
...
...
@@ -360,7 +360,6 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
}
}
catch
(
error
)
{
self
.
emit
(
'complete.error'
,
error
);
throw
error
;
}
};
...
...
@@ -1372,7 +1371,6 @@ Casper.prototype.runStep = function runStep(step) {
}
}
catch
(
err
)
{
this
.
emit
(
'step.error'
,
err
);
throw
err
;
}
if
(
!
skipLog
)
{
this
.
emit
(
'step.complete'
,
stepResult
);
...
...
modules/tester.js
View file @
583d1e7
...
...
@@ -259,7 +259,7 @@ Tester.prototype.assertTrue = function assert(subject, message, context) {
}
},
context
||
{});
if
(
!
result
.
success
&&
result
.
doThrow
)
{
throw
new
AssertionError
(
message
,
result
);
throw
new
AssertionError
(
message
||
result
.
standard
,
result
);
}
return
this
.
processAssertionResult
(
result
);
};
...
...
tests/clitests/error/syntax.js
0 → 100644
View file @
583d1e7
qsfjdhf
!
è
r
è"è
qwnfkmsghfkswjdgfjksn
tests/clitests/runtests.py
View file @
583d1e7
...
...
@@ -81,6 +81,20 @@ class CasperExecTest(unittest.TestCase):
self
.
assertCommandOutputEquals
(
script_path
,
'it works'
)
@timeout
(
20
)
def
test_syntax_error
(
self
):
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'error'
,
'syntax.js'
)
self
.
assertCommandOutputContains
(
script_path
,
[
'SyntaxError: Parse error'
,
],
failing
=
True
)
@timeout
(
20
)
def
test_syntax_error_in_test
(
self
):
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'error'
,
'syntax.js'
)
self
.
assertCommandOutputContains
(
'test
%
s'
%
script_path
,
[
'SyntaxError: Parse error'
,
],
failing
=
True
)
@timeout
(
20
)
def
test_simple_test_script
(
self
):
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'tester'
,
'mytest.js'
)
self
.
assertCommandOutputContains
(
'test '
+
script_path
,
[
...
...
Please
register
or
sign in
to post a comment