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
adb1b042
...
adb1b04297f0d141d7ebcc0052cf6c838c166283
authored
2013-02-22 12:38:21 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
now relying on phantomjs native require()
1 parent
64d7050f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
48 additions
and
101 deletions
bin/bootstrap.js
modules/casper.js
modules/cli.js
modules/colorizer.js
modules/http.js
modules/mouse.js
modules/pagestack.js
modules/tester.js
modules/utils.js
modules/xunit.js
tests/run.js
bin/bootstrap.js
View file @
adb1b04
...
...
@@ -69,106 +69,40 @@ if (typeof Function.prototype.bind !== "function") {
*/
function
patchRequire
(
require
,
requireDirs
)
{
"use strict"
;
require
(
'webserver'
);
// force generation of phantomjs' require.cache for the webserver module
var
fs
=
require
(
'fs'
);
var
phantomBuiltins
=
[
'fs'
,
'webpage'
,
'system'
,
'webserver'
];
var
phantomRequire
=
phantom
.
__orig__require
=
require
;
var
requireCache
=
{};
function
possiblePaths
(
path
,
requireDir
)
{
var
dir
,
paths
=
[];
if
(
path
[
0
]
===
'.'
)
{
paths
.
push
.
apply
(
paths
,
[
fs
.
absolute
(
path
),
fs
.
absolute
(
fs
.
pathJoin
(
requireDir
,
path
))
]);
}
else
if
(
path
[
0
]
===
'/'
)
{
paths
.
push
(
path
);
}
else
{
dir
=
fs
.
absolute
(
requireDir
);
while
(
dir
!==
''
&&
dir
.
lastIndexOf
(
':'
)
!==
dir
.
length
-
1
)
{
paths
.
push
(
fs
.
pathJoin
(
dir
,
'modules'
,
path
));
// nodejs compatibility
paths
.
push
(
fs
.
pathJoin
(
dir
,
'node_modules'
,
path
));
dir
=
fs
.
dirname
(
dir
);
}
paths
.
push
(
fs
.
pathJoin
(
requireDir
,
'lib'
,
path
));
paths
.
push
(
fs
.
pathJoin
(
requireDir
,
'modules'
,
path
));
}
return
paths
;
if
(
require
.
patched
)
{
return
require
;
}
var
patchedRequire
=
function
_require
(
path
)
{
var
i
,
paths
=
[],
fileGuesses
=
[],
file
,
module
=
{
exports
:
{}
};
if
(
phantomBuiltins
.
indexOf
(
path
)
!==
-
1
)
{
return
phantomRequire
(
path
);
}
requireDirs
.
forEach
(
function
(
requireDir
)
{
paths
=
paths
.
concat
(
possiblePaths
(
path
,
requireDir
));
var
fs
=
require
(
'fs'
),
moduleFilePath
;
var
modulesPath
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'modules'
);
var
casperModules
=
fs
.
list
(
modulesPath
).
filter
(
function
(
entry
)
{
var
absPath
=
fs
.
absolute
(
fs
.
pathJoin
(
modulesPath
,
entry
));
return
entry
!==
"."
&&
entry
!==
".."
&&
!
fs
.
isDirectory
(
absPath
);
}).
map
(
function
(
moduleFile
)
{
return
moduleFile
.
replace
(
/
\.
js$/
,
''
);
});
paths
.
forEach
(
function
_forEach
(
testPath
)
{
fileGuesses
.
push
.
apply
(
fileGuesses
,
[
testPath
,
testPath
+
'.js'
,
testPath
+
'.json'
,
testPath
+
'.coffee'
,
fs
.
pathJoin
(
testPath
,
'index.js'
),
fs
.
pathJoin
(
testPath
,
'index.json'
),
fs
.
pathJoin
(
testPath
,
'index.coffee'
),
fs
.
pathJoin
(
testPath
,
'lib'
,
fs
.
basename
(
testPath
)
+
'.js'
),
fs
.
pathJoin
(
testPath
,
'lib'
,
fs
.
basename
(
testPath
)
+
'.json'
),
fs
.
pathJoin
(
testPath
,
'lib'
,
fs
.
basename
(
testPath
)
+
'.coffee'
)
]);
});
file
=
null
;
for
(
i
=
0
;
i
<
fileGuesses
.
length
&&
!
file
;
++
i
)
{
if
(
fs
.
isFile
(
fileGuesses
[
i
]))
{
file
=
fileGuesses
[
i
];
}
}
if
(
!
file
)
{
throw
new
window
.
CasperError
(
"CasperJS couldn't find module "
+
path
);
}
if
(
file
in
requireCache
)
{
return
requireCache
[
file
].
exports
;
}
if
(
/
\.
json/i
.
test
(
file
))
{
var
parsed
=
JSON
.
parse
(
fs
.
read
(
file
));
requireCache
[
file
]
=
parsed
;
return
parsed
;
}
var
scriptCode
=
(
function
getScriptCode
(
file
)
{
var
scriptCode
=
fs
.
read
(
file
);
if
(
/
\.
coffee$/i
.
test
(
file
))
{
/*global CoffeeScript*/
try
{
scriptCode
=
CoffeeScript
.
compile
(
scriptCode
);
}
catch
(
e
)
{
throw
new
Error
(
'Unable to compile coffeescript:'
+
e
);
}
}
return
scriptCode
;
})(
file
);
var
fn
=
new
Function
(
'__file__'
,
'require'
,
'module'
,
'exports'
,
scriptCode
);
try
{
fn
(
file
,
_require
,
module
,
module
.
exports
);
if
(
casperModules
.
indexOf
(
path
)
>
-
1
)
{
moduleFilePath
=
fs
.
pathJoin
(
modulesPath
,
path
+
'.js'
);
return
require
(
moduleFilePath
);
}
return
require
(
path
);
}
catch
(
e
)
{
var
error
=
new
window
.
CasperError
(
'__mod_error('
+
path
+
':'
+
e
.
line
+
'):: '
+
e
);
error
.
file
=
file
;
error
.
line
=
e
.
line
;
error
.
stack
=
e
.
stack
;
error
.
stackArray
=
JSON
.
parse
(
JSON
.
stringify
(
e
.
stackArray
));
if
(
error
.
stackArray
.
length
>
0
)
{
error
.
stackArray
[
0
].
sourceURL
=
file
;
if
(
moduleFilePath
)
{
var
error
=
new
window
.
CasperError
(
'__mod_error('
+
path
+
':'
+
e
.
line
+
'):: '
+
e
);
error
.
file
=
moduleFilePath
;
error
.
line
=
e
.
line
;
error
.
stack
=
e
.
stack
;
error
.
stackArray
=
JSON
.
parse
(
JSON
.
stringify
(
e
.
stackArray
));
if
(
error
.
stackArray
.
length
>
0
)
{
error
.
stackArray
[
0
].
sourceURL
=
moduleFilePath
;
}
throw
error
;
}
throw
e
rror
;
throw
e
;
}
requireCache
[
file
]
=
module
;
return
module
.
exports
;
};
patchedRequire
.
cache
=
require
.
cache
;
patchedRequire
.
patched
=
true
;
return
patchedRequire
;
}
...
...
modules/casper.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError console exports phantom
require __utils__
*/
/*global CasperError console exports phantom
__utils__ patchRequire
*/
var
require
=
patchRequire
(
require
);
var
colorizer
=
require
(
'colorizer'
);
var
events
=
require
(
'events'
);
var
fs
=
require
(
'fs'
);
...
...
modules/cli.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError console exports phantom
r
equire*/
/*global CasperError console exports phantom
patchR
equire*/
var
require
=
patchRequire
(
require
);
var
system
=
require
(
'system'
);
var
utils
=
require
(
'utils'
);
...
...
modules/colorizer.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global exports console
r
equire*/
/*global exports console
patchR
equire*/
var
require
=
patchRequire
(
require
);
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
...
...
modules/http.js
View file @
adb1b04
...
...
@@ -28,6 +28,9 @@
*
*/
/*global patchRequire*/
var
require
=
patchRequire
(
require
);
var
utils
=
require
(
'utils'
);
/*
...
...
modules/mouse.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError exports
r
equire*/
/*global CasperError exports
patchR
equire*/
var
require
=
patchRequire
(
require
);
var
utils
=
require
(
'utils'
);
exports
.
create
=
function
create
(
casper
)
{
...
...
modules/pagestack.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError console exports phantom
r
equire*/
/*global CasperError console exports phantom
patchR
equire*/
var
require
=
patchRequire
(
require
);
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
...
...
modules/tester.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError exports phantom
require __utils__
*/
/*global CasperError exports phantom
__utils__ patchRequire
*/
var
require
=
patchRequire
(
require
);
var
fs
=
require
(
'fs'
);
var
events
=
require
(
'events'
);
var
utils
=
require
(
'utils'
);
...
...
modules/utils.js
View file @
adb1b04
...
...
@@ -28,7 +28,9 @@
*
*/
/*global CasperError console exports phantom require*/
/*global CasperError console exports phantom patchRequire*/
var
require
=
patchRequire
(
require
);
/**
* Provides a better typeof operator equivalent, able to retrieve the array
...
...
modules/xunit.js
View file @
adb1b04
...
...
@@ -28,8 +28,9 @@
*
*/
/*global CasperError console exports phantom
r
equire*/
/*global CasperError console exports phantom
patchR
equire*/
var
require
=
patchRequire
(
require
);
var
utils
=
require
(
'utils'
);
var
fs
=
require
(
'fs'
);
var
TestSuiteResult
=
require
(
'tester'
).
TestSuiteResult
;
...
...
tests/run.js
View file @
adb1b04
/*global phantom CasperError*/
/*global phantom CasperError
patchRequire
*/
if
(
!
phantom
.
casperLoaded
)
{
console
.
log
(
'This script must be invoked using the casperjs executable'
);
phantom
.
exit
(
1
);
}
var
require
=
patchRequire
(
require
);
var
fs
=
require
(
'fs'
);
var
colorizer
=
require
(
'colorizer'
);
var
utils
=
require
(
'utils'
);
...
...
Please
register
or
sign in
to post a comment