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
cea904e9
...
cea904e99be3029ccfe4d1c8690071e321fce2c5
authored
2012-01-02 20:50:27 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactored xunit.js module
1 parent
95a987c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
64 deletions
modules/utils.js
modules/xunit.js
modules/utils.js
View file @
cea904e
...
...
@@ -236,6 +236,25 @@ function mergeObjects(obj1, obj2) {
exports
.
mergeObjects
=
mergeObjects
;
/**
* Creates an (SG|X)ML node element.
*
* @param String name The node name
* @param Object attributes Optional attributes
* @return HTMLElement
*/
function
node
(
name
,
attributes
)
{
var
node
=
document
.
createElement
(
name
);
for
(
var
attrName
in
attributes
)
{
var
value
=
attributes
[
attrName
];
if
(
attributes
.
hasOwnProperty
(
attrName
)
&&
isString
(
attrName
))
{
node
.
setAttribute
(
attrName
,
value
);
}
}
return
node
;
}
exports
.
node
=
node
;
/**
* Serializes a value using JSON.
*
* @param Mixed value
...
...
@@ -265,13 +284,13 @@ exports.serialize = serialize;
* @param {function} superCtor Constructor function to inherit prototype from.
*/
exports
.
inherits
=
function
(
ctor
,
superCtor
)
{
ctor
.
super_
=
superCtor
;
ctor
.
prototype
=
Object
.
create
(
superCtor
.
prototype
,
{
constructor
:
{
value
:
ctor
,
enumerable
:
false
,
writable
:
true
,
configurable
:
true
}
});
ctor
.
super_
=
superCtor
;
ctor
.
prototype
=
Object
.
create
(
superCtor
.
prototype
,
{
constructor
:
{
value
:
ctor
,
enumerable
:
false
,
writable
:
true
,
configurable
:
true
}
});
};
...
...
modules/xunit.js
View file @
cea904e
...
...
@@ -37,64 +37,52 @@ exports.create = function() {
*
*/
XUnitExporter
=
function
()
{
var
node
=
function
(
name
,
attributes
)
{
var
node
=
document
.
createElement
(
name
);
for
(
var
attrName
in
attributes
)
{
var
value
=
attributes
[
attrName
];
if
(
attributes
.
hasOwnProperty
(
attrName
)
&&
utils
.
isType
(
attrName
,
"string"
))
{
node
.
setAttribute
(
attrName
,
value
);
}
}
return
node
;
};
var
xml
=
node
(
'testsuite'
);
xml
.
toString
=
function
()
{
this
.
_xml
=
utils
.
node
(
'testsuite'
);
this
.
_xml
.
toString
=
function
()
{
return
this
.
outerHTML
;
// ouch
};
};
exports
.
XUnitExporter
=
XUnitExporter
;
/**
* Adds a successful test result
*
* @param String classname
* @param String name
*/
this
.
addSuccess
=
function
(
classname
,
name
)
{
xml
.
appendChild
(
node
(
'testcase'
,
{
classname
:
classname
,
name
:
name
}));
};
/**
* Adds a failed test result
*
* @param String classname
* @param String name
* @param String message
* @param String type
*/
this
.
addFailure
=
function
(
classname
,
name
,
message
,
type
)
{
var
fnode
=
node
(
'testcase'
,
{
classname
:
classname
,
name
:
name
});
var
failure
=
node
(
'failure'
,
{
type
:
type
||
"unknown"
});
failure
.
appendChild
(
document
.
createTextNode
(
message
||
"no message left"
));
fnode
.
appendChild
(
failure
);
xml
.
appendChild
(
fnode
);
};
/**
* Adds a successful test result
*
* @param String classname
* @param String name
*/
XUnitExporter
.
prototype
.
addSuccess
=
function
(
classname
,
name
)
{
this
.
_xml
.
appendChild
(
utils
.
node
(
'testcase'
,
{
classname
:
classname
,
name
:
name
}));
};
/**
* Retrieves generated XML object - actually an HTMLElement.
*
* @return HTMLElement
*/
this
.
getXML
=
function
()
{
return
xml
;
};
/**
* Adds a failed test result
*
* @param String classname
* @param String name
* @param String message
* @param String type
*/
XUnitExporter
.
prototype
.
addFailure
=
function
(
classname
,
name
,
message
,
type
)
{
var
fnode
=
utils
.
node
(
'testcase'
,
{
classname
:
classname
,
name
:
name
});
var
failure
=
utils
.
node
(
'failure'
,
{
type
:
type
||
"unknown"
});
failure
.
appendChild
(
document
.
createTextNode
(
message
||
"no message left"
));
fnode
.
appendChild
(
failure
);
this
.
_xml
.
appendChild
(
fnode
);
};
exports
.
XUnitExporter
=
XUnitExporter
;
/**
* Retrieves generated XML object - actually an HTMLElement.
*
* @return HTMLElement
*/
XUnitExporter
.
prototype
.
getXML
=
function
()
{
return
this
.
_xml
;
};
...
...
Please
register
or
sign in
to post a comment