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
125c37f0
...
125c37f0f2099de3ae7a18e30d179c69f2bd05de
authored
2012-12-10 08:48:28 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added JSON support to require()
1 parent
68b32572
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
2 deletions
CHANGELOG.md
bin/bootstrap.js
tests/sample_modules/config.json
tests/suites/require.js
CHANGELOG.md
View file @
125c37f
...
...
@@ -94,6 +94,7 @@ Also, `Casper.mouseEvent()` will now directly trigger an error on failure instea
-
fixed
[
#290
](
https://github.com/n1k0/casperjs/issues/#290
)
- add a simplistic RPM spec file to make it easier to (un)install casperjs
-
fixed
[
`utils.betterTypeOf()`
](
http://casperjs.org/api.html#casper.betterTypeOf
)
to properly handle
`undefined`
and
`null`
values
-
fixed
`Casper.die()`
and
`Casper.evaluateOrDie()`
were not printing the error onto the console
-
added JSON support to
`require()`
-
added
[
`Casper.sendKeys()`
](
http://casperjs.org/api.html#casper.sendKeys
)
to send native keyboard events to the element matching a given selector
-
added
[
`Casper.getFormValues()`
](
http://casperjs.org/api.html#casper.getFormValues
)
to check for the field values of a given form
-
added
[
`Tester.assertTextDoesntExist()`
](
http://casperjs.org/api.html#tester.assertTextDoesntExist
)
...
...
bin/bootstrap.js
View file @
125c37f
...
...
@@ -106,10 +106,13 @@ function patchRequire(require, requireDirs) {
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'
)
]);
});
...
...
@@ -125,6 +128,11 @@ function patchRequire(require, requireDirs) {
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
))
{
...
...
tests/sample_modules/config.json
0 → 100644
View file @
125c37f
{
"ok"
:
true
}
tests/suites/require.js
View file @
125c37f
...
...
@@ -2,7 +2,7 @@
/*jshint strict:false*/
var
fs
=
require
(
'fs'
);
var
modroot
=
fs
.
pathJoin
(
phantom
.
casperPath
,
'tests'
,
'sample_modules'
);
var
jsmod
,
csmod
;
var
jsmod
,
csmod
,
config
;
casper
.
test
.
comment
(
'Javascript module loading'
)
try
{
...
...
@@ -20,4 +20,12 @@ try {
casper
.
test
.
fail
(
'require() patched version can load a coffeescript module'
);
}
casper
.
test
.
done
(
2
);
casper
.
test
.
comment
(
'JSON module loading'
)
try
{
config
=
require
(
fs
.
pathJoin
(
modroot
,
'config.json'
));
casper
.
test
.
assertTrue
(
config
.
ok
,
'require() patched version can load a json module'
);
}
catch
(
e
)
{
casper
.
test
.
fail
(
'require() patched version can load a json module'
);
}
casper
.
test
.
done
(
3
);
...
...
Please
register
or
sign in
to post a comment