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
83a68850
...
83a688508b400b6f3bc4dd0049f9ab8229b8aa36
authored
2012-09-07 19:08:19 +0200
by
Julien Moulin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refacto for pre/post
1 parent
428f8000
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
44 deletions
modules/tester.js
tests/run.js
modules/tester.js
View file @
83a6885
...
...
@@ -55,9 +55,11 @@ var Tester = function Tester(casper, options) {
this
.
currentTestFile
=
null
;
this
.
exporter
=
require
(
'xunit'
).
create
();
this
.
includes
=
[];
this
.
pre
=
[];
this
.
post
=
[];
this
.
loadIncludes
=
{
includes
:
[],
pre
:
[],
post
:
[]
};
this
.
running
=
false
;
this
.
suites
=
[];
this
.
options
=
utils
.
mergeObjects
({
...
...
@@ -723,21 +725,29 @@ var Tester = function Tester(casper, options) {
if
(
arguments
.
length
===
0
)
{
throw
new
CasperError
(
"runSuites() needs at least one path argument"
);
}
this
.
includes
.
forEach
(
function
(
include
)
{
this
.
loadIncludes
.
includes
.
forEach
(
function
(
include
)
{
phantom
.
injectJs
(
include
);
});
this
.
loadIncludes
.
pre
.
forEach
(
function
(
include
)
{
testFiles
=
testFiles
.
concat
(
include
);
});
Array
.
prototype
.
forEach
.
call
(
arguments
,
function
_forEach
(
path
)
{
if
(
!
fs
.
exists
(
path
))
{
self
.
bar
(
f
(
"Path %s doesn't exist"
,
path
),
"RED_BAR"
);
}
if
(
fs
.
isDirectory
(
path
))
{
testFiles
=
testFiles
.
concat
(
this
.
pre
);
testFiles
=
testFiles
.
concat
(
self
.
findTestFiles
(
path
));
testFiles
=
testFiles
.
concat
(
this
.
post
);
}
else
if
(
fs
.
isFile
(
path
))
{
testFiles
.
push
(
path
);
}
});
this
.
loadIncludes
.
post
.
forEach
(
function
(
include
)
{
testFiles
=
testFiles
.
concat
(
include
);
});
if
(
testFiles
.
length
===
0
)
{
this
.
bar
(
f
(
"No test file found in %s, aborting."
,
Array
.
prototype
.
slice
.
call
(
arguments
)),
"RED_BAR"
);
casper
.
exit
(
1
);
...
...
tests/run.js
View file @
83a6885
...
...
@@ -3,14 +3,12 @@ if (!phantom.casperLoaded) {
phantom
.
exit
(
1
);
}
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
var
includes
=
[];
var
pre
=
[];
var
post
=
[];
var
tests
=
[];
var
casper
=
require
(
'casper'
).
create
({
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
var
loadIncludes
=
[
'includes'
,
'pre'
,
'post'
];
var
tests
=
[];
var
casper
=
require
(
'casper'
).
create
({
exitOnError
:
false
});
...
...
@@ -56,37 +54,18 @@ if (casper.cli.args.length) {
}
// includes handling
if
(
casper
.
cli
.
has
(
'includes'
))
{
includes
=
casper
.
cli
.
get
(
'includes'
).
split
(
','
).
map
(
function
(
include
)
{
// we can't use filter() directly because of abspath transformation
return
checkIncludeFile
(
include
);
}).
filter
(
function
(
include
)
{
return
utils
.
isString
(
include
);
});
casper
.
test
.
includes
=
utils
.
unique
(
includes
);
}
// pre handling
if
(
casper
.
cli
.
has
(
'pre'
))
{
pre
=
casper
.
cli
.
get
(
'pre'
).
split
(
','
).
map
(
function
(
unique_pre
)
{
// we can't use filter() directly because of abspath transformation
return
checkIncludeFile
(
unique_pre
);
}).
filter
(
function
(
unique_pre
)
{
return
utils
.
isString
(
unique_pre
);
});
casper
.
test
.
pre
=
utils
.
unique
(
pre
);
}
this
.
loadIncludes
.
forEach
(
function
(
include
){
var
container
;
if
(
casper
.
cli
.
has
(
include
))
{
container
=
casper
.
cli
.
get
(
include
).
split
(
','
).
map
(
function
(
file
)
{
return
checkIncludeFile
(
file
);
}).
filter
(
function
(
file
)
{
return
utils
.
isString
(
file
);
});
// post handling
if
(
casper
.
cli
.
has
(
'post'
))
{
post
=
casper
.
cli
.
get
(
'post'
).
split
(
','
).
map
(
function
(
unique_post
)
{
// we can't use filter() directly because of abspath transformation
return
checkIncludeFile
(
unique_post
);
}).
filter
(
function
(
unique_post
)
{
return
utils
.
isString
(
unique_post
);
});
casper
.
test
.
post
=
utils
.
unique
(
post
);
}
casper
.
test
.
loadIncludes
[
include
]
=
utils
.
unique
(
container
);
}
});
// test suites completion listener
casper
.
test
.
on
(
'tests.complete'
,
function
()
{
...
...
Please
register
or
sign in
to post a comment