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
56b1de63
...
56b1de630aa45ff437a34cc85002278e7729b429
authored
2012-01-18 11:02:38 +0200
by
Mikko Peltonen
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Use file name of test script as 'classname' in JUnit XML report
1 parent
d9398c31
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
19 deletions
modules/tester.js
modules/xunit.js
tests/suites/xunit.js
modules/tester.js
View file @
56b1de6
...
...
@@ -47,7 +47,7 @@ var Tester = function(casper, options) {
}
this
.
currentTestFile
=
null
;
this
.
exporter
=
require
(
'xunit'
).
create
();
this
.
exporter
=
require
(
'xunit'
).
create
(
casper
);
this
.
running
=
false
;
this
.
suites
=
[];
this
.
options
=
utils
.
mergeObjects
({
...
...
@@ -86,13 +86,13 @@ var Tester = function(casper, options) {
eventName
=
'success'
;
style
=
'INFO'
;
this
.
testResults
.
passed
++
;
this
.
exporter
.
addSuccess
(
"unknown"
,
message
);
this
.
exporter
.
addSuccess
(
message
);
}
else
{
eventName
=
'fail'
;
status
=
this
.
options
.
failText
;
style
=
'RED_BAR'
;
this
.
testResults
.
failed
++
;
this
.
exporter
.
addFailure
(
"unknown"
,
message
,
'test failed'
,
"assert"
);
this
.
exporter
.
addFailure
(
message
,
'test failed'
,
"assert"
);
}
this
.
emit
(
eventName
,
{
message
:
message
,
...
...
@@ -114,14 +114,14 @@ var Tester = function(casper, options) {
eventName
=
"success"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
passText
,
'INFO'
)
+
' '
+
this
.
formatMessage
(
message
));
this
.
testResults
.
passed
++
;
this
.
exporter
.
addSuccess
(
"unknown"
,
message
);
this
.
exporter
.
addSuccess
(
message
);
}
else
{
eventName
=
"fail"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
failText
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
' got: '
+
utils
.
serialize
(
testValue
));
this
.
comment
(
' expected: '
+
utils
.
serialize
(
expected
));
this
.
testResults
.
failed
++
;
this
.
exporter
.
addFailure
(
"unknown"
,
message
,
f
(
"test failed; expected: %s; got: %s"
,
expected
,
testValue
),
"assertEquals"
);
this
.
exporter
.
addFailure
(
message
,
f
(
"test failed; expected: %s; got: %s"
,
expected
,
testValue
),
"assertEquals"
);
}
this
.
emit
(
eventName
,
{
message
:
message
,
...
...
@@ -175,14 +175,14 @@ var Tester = function(casper, options) {
eventName
=
"success"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
passText
,
'INFO'
)
+
' '
+
this
.
formatMessage
(
message
));
this
.
testResults
.
passed
++
;
this
.
exporter
.
addSuccess
(
"unknown"
,
message
);
this
.
exporter
.
addSuccess
(
message
);
}
else
{
eventName
=
"fail"
;
casper
.
echo
(
this
.
colorize
(
this
.
options
.
failText
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
' subject: '
+
subject
);
this
.
comment
(
' pattern: '
+
pattern
.
toString
());
this
.
testResults
.
failed
++
;
this
.
exporter
.
addFailure
(
"unknown"
,
message
,
f
(
"test failed; subject: %s; pattern: %s"
,
subject
,
pattern
.
toString
()),
"assertMatch"
);
this
.
exporter
.
addFailure
(
message
,
f
(
"test failed; subject: %s; pattern: %s"
,
subject
,
pattern
.
toString
()),
"assertMatch"
);
}
this
.
emit
(
eventName
,
{
message
:
message
,
...
...
modules/xunit.js
View file @
56b1de6
...
...
@@ -29,16 +29,18 @@
*/
var
utils
=
require
(
'utils'
);
var
fs
=
require
(
'fs'
);
exports
.
create
=
function
()
{
return
new
XUnitExporter
();
exports
.
create
=
function
(
casper
)
{
return
new
XUnitExporter
(
casper
);
};
/**
* JUnit XML (xUnit) exporter for test results.
*
*/
XUnitExporter
=
function
()
{
XUnitExporter
=
function
(
casper
)
{
this
.
_casper
=
casper
this
.
_xml
=
utils
.
node
(
'testsuite'
);
this
.
_xml
.
toString
=
function
()
{
return
this
.
outerHTML
;
// ouch
...
...
@@ -52,9 +54,9 @@ exports.XUnitExporter = XUnitExporter;
* @param String classname
* @param String name
*/
XUnitExporter
.
prototype
.
addSuccess
=
function
(
classname
,
name
)
{
XUnitExporter
.
prototype
.
addSuccess
=
function
(
name
)
{
this
.
_xml
.
appendChild
(
utils
.
node
(
'testcase'
,
{
classname
:
classname
,
classname
:
generateClassName
(
this
.
_casper
)
,
name
:
name
}));
};
...
...
@@ -67,9 +69,9 @@ XUnitExporter.prototype.addSuccess = function(classname, name) {
* @param String message
* @param String type
*/
XUnitExporter
.
prototype
.
addFailure
=
function
(
classname
,
name
,
message
,
type
)
{
XUnitExporter
.
prototype
.
addFailure
=
function
(
name
,
message
,
type
)
{
var
fnode
=
utils
.
node
(
'testcase'
,
{
classname
:
classname
,
classname
:
generateClassName
(
this
.
_casper
)
,
name
:
name
});
var
failure
=
utils
.
node
(
'failure'
,
{
...
...
@@ -81,6 +83,23 @@ XUnitExporter.prototype.addFailure = function(classname, name, message, type) {
};
/**
* Generates a value for 'classname' attribute of the JUnit XML report
*
* Uses the (relative) file name of the current casper script without file
* extension as classname.
*
* @params Casper
* @return String
*/
function
generateClassName
(
casper
)
{
var
script
=
casper
.
test
.
currentTestFile
||
phantom
.
casperScript
||
"unknown"
;
if
(
script
.
indexOf
(
fs
.
workingDirectory
)
===
0
)
{
script
=
script
.
substring
(
fs
.
workingDirectory
.
length
+
1
);
}
return
script
.
substring
(
0
,
script
.
lastIndexOf
(
'.'
));
}
/**
* Retrieves generated XML object - actually an HTMLElement.
*
* @return HTMLElement
...
...
tests/suites/xunit.js
View file @
56b1de6
casper
.
test
.
comment
(
'phantom.Casper.XUnitExporter'
);
xunit
=
require
(
'xunit'
).
create
();
xunit
.
addSuccess
(
'
foo'
,
'
bar'
);
casper
.
test
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="
foo
" name="bar"/
,
'XUnitExporter.addSuccess() adds a successful testcase'
);
xunit
.
addFailure
(
'ba
r'
,
'ba
z'
,
'wrong'
,
'chucknorriz'
);
casper
.
test
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="
bar
" name="baz"><failure type="chucknorriz">wrong/
,
'XUnitExporter.addFailure() adds a failed testcase'
);
xunit
=
require
(
'xunit'
).
create
(
casper
);
xunit
.
addSuccess
(
'bar'
);
casper
.
test
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="
tests
\/
suites
\/
xunit
" name="bar"/
,
'XUnitExporter.addSuccess() adds a successful testcase'
);
xunit
.
addFailure
(
'baz'
,
'wrong'
,
'chucknorriz'
);
casper
.
test
.
assertMatch
(
xunit
.
getXML
(),
/<testcase classname="
tests
\/
suites
\/
xunit
" name="baz"><failure type="chucknorriz">wrong/
,
'XUnitExporter.addFailure() adds a failed testcase'
);
casper
.
test
.
done
();
...
...
Please
register
or
sign in
to post a comment