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
eb4be25d
...
eb4be25d4122410d64db845b644ab630c6eebd3a
authored
2013-09-09 05:43:14 -0700
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #609 from laurentj/issue-601
Fixes a regression on sub module loading
2 parents
1031b264
a6e6b04f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
5 deletions
bin/bootstrap.js
tests/clitests/modules/test_patched_require.js
tests/clitests/runtests.py
bin/bootstrap.js
View file @
eb4be25
...
...
@@ -190,9 +190,9 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
var
basenames
=
[
path
,
path
+
'/index'
];
var
paths
=
[];
basenames
.
forEach
(
function
(
basename
)
{
paths
.
push
(
fs
.
pathJoin
(
dir
,
basename
));
paths
.
push
(
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
basename
)
));
extensions
.
forEach
(
function
(
extension
)
{
paths
.
push
(
fs
.
pathJoin
(
dir
,
[
basename
,
extension
].
join
(
'.'
)));
paths
.
push
(
fs
.
absolute
(
fs
.
pathJoin
(
dir
,
[
basename
,
extension
].
join
(
'.'
)
)));
});
});
for
(
var
i
=
0
;
i
<
paths
.
length
;
i
++
)
{
...
...
@@ -200,6 +200,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
return
paths
[
i
];
}
}
return
null
;
}
function
getCurrentScriptRoot
()
{
if
((
phantom
.
casperScriptBaseDir
||
""
).
indexOf
(
fs
.
workingDirectory
)
===
0
)
{
...
...
tests/clitests/modules/test_patched_require.js
0 → 100644
View file @
eb4be25
var
require
=
patchRequire
(
require
);
var
casper
=
require
(
'casper'
).
create
();
var
mod
=
require
(
'./mod'
);
console
.
log
(
mod
.
hello
);
casper
.
exit
();
tests/clitests/runtests.py
View file @
eb4be25
...
...
@@ -9,7 +9,11 @@ import unittest
TEST_ROOT
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
CASPERJS_ROOT
=
os
.
path
.
abspath
(
os
.
path
.
join
(
TEST_ROOT
,
'..'
,
'..'
))
CASPER_EXEC
=
os
.
path
.
join
(
CASPERJS_ROOT
,
'bin'
,
'casperjs'
)
PHANTOMJS_EXEC
=
os
.
environ
[
'PHANTOMJS_EXECUTABLE'
]
# make it to an absolute path, because some test change the working directory
# and relative path to phantomjs would be invalid
if
not
os
.
path
.
isabs
(
PHANTOMJS_EXEC
):
os
.
environ
[
'PHANTOMJS_EXECUTABLE'
]
=
os
.
path
.
join
(
CASPERJS_ROOT
,
PHANTOMJS_EXEC
)
class
TimeoutException
(
Exception
):
pass
...
...
@@ -49,7 +53,7 @@ class CasperExecTestBase(unittest.TestCase):
except
subprocess
.
CalledProcessError
as
err
:
if
failing
:
return
err
.
output
.
decode
(
'utf-8'
)
raise
IOError
(
'Command
%
s exited:
%
s
'
%
(
cmd
,
err
))
raise
IOError
(
'Command
%
s exited:
%
s
\n
%
s'
%
(
cmd
,
err
,
err
.
output
.
decode
(
'utf-8'
)
))
def
assertCommandOutputEquals
(
self
,
cmd
,
result
,
**
kwargs
):
self
.
assertEqual
(
self
.
runCommand
(
cmd
),
result
)
...
...
@@ -74,7 +78,7 @@ class BasicCommandsTest(CasperExecTestBase):
self
.
assertCommandOutputContains
(
'--help'
,
self
.
pkg_version
)
class
RequireTest
(
CasperExecTestBase
):
class
Require
ScriptFullPath
Test
(
CasperExecTestBase
):
@timeout
(
20
)
def
test_simple_require
(
self
):
script_path
=
os
.
path
.
join
(
TEST_ROOT
,
'modules'
,
'test.js'
)
...
...
@@ -101,6 +105,77 @@ class RequireTest(CasperExecTestBase):
self
.
assertCommandOutputEquals
(
script_path
,
'42'
)
class
RequireWithOnlyScriptNameTest
(
CasperExecTestBase
):
def
setUp
(
self
):
self
.
currentPath
=
os
.
getcwd
()
os
.
chdir
(
os
.
path
.
join
(
TEST_ROOT
,
'modules'
))
super
(
RequireWithOnlyScriptNameTest
,
self
)
.
setUp
()
def
tearDown
(
self
):
os
.
chdir
(
self
.
currentPath
)
super
(
RequireWithOnlyScriptNameTest
,
self
)
.
tearDown
()
@timeout
(
20
)
def
test_simple_require
(
self
):
self
.
assertCommandOutputEquals
(
'test.js'
,
'hello, world'
)
@timeout
(
20
)
def
test_simple_patched_require
(
self
):
self
.
assertCommandOutputEquals
(
'test_patched_require.js'
,
'hello, world'
)
@timeout
(
20
)
def
test_require_coffee
(
self
):
self
.
assertCommandOutputEquals
(
'test_coffee.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require
(
self
):
self
.
assertCommandOutputEquals
(
'test_node_mod.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require_index
(
self
):
self
.
assertCommandOutputEquals
(
'test_node_mod_index.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require_json
(
self
):
self
.
assertCommandOutputEquals
(
'test_node_json.js'
,
'42'
)
class
RequireWithRelativeScriptPathTest
(
CasperExecTestBase
):
def
setUp
(
self
):
self
.
currentPath
=
os
.
getcwd
()
os
.
chdir
(
os
.
path
.
join
(
TEST_ROOT
,
'modules'
))
super
(
RequireWithRelativeScriptPathTest
,
self
)
.
setUp
()
def
tearDown
(
self
):
os
.
chdir
(
self
.
currentPath
)
super
(
RequireWithRelativeScriptPathTest
,
self
)
.
tearDown
()
@timeout
(
20
)
def
test_simple_require
(
self
):
self
.
assertCommandOutputEquals
(
'./test.js'
,
'hello, world'
)
@timeout
(
20
)
def
test_simple_patched_require
(
self
):
self
.
assertCommandOutputEquals
(
'test_patched_require.js'
,
'hello, world'
)
@timeout
(
20
)
def
test_require_coffee
(
self
):
self
.
assertCommandOutputEquals
(
'./test_coffee.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require
(
self
):
self
.
assertCommandOutputEquals
(
'./test_node_mod.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require_index
(
self
):
self
.
assertCommandOutputEquals
(
'./test_node_mod_index.js'
,
'42'
)
@timeout
(
20
)
def
test_node_module_require_json
(
self
):
self
.
assertCommandOutputEquals
(
'./test_node_json.js'
,
'42'
)
class
ScriptOutputTest
(
CasperExecTestBase
):
@timeout
(
20
)
def
test_simple_script
(
self
):
...
...
Please
register
or
sign in
to post a comment