diff options
| author | Misko Hevery | 2012-03-23 14:03:24 -0700 |
|---|---|---|
| committer | Misko Hevery | 2012-03-28 11:16:35 -0700 |
| commit | 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (patch) | |
| tree | e7529b741d70199f36d52090b430510bad07f233 /src/ngScenario/output/Xml.js | |
| parent | 944098a4e0f753f06b40c73ca3e79991cec6c2e2 (diff) | |
| download | angular.js-2430f52bb97fa9d682e5f028c977c5bf94c5ec38.tar.bz2 | |
chore(module): move files around in preparation for more modules
Diffstat (limited to 'src/ngScenario/output/Xml.js')
| -rw-r--r-- | src/ngScenario/output/Xml.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/ngScenario/output/Xml.js b/src/ngScenario/output/Xml.js new file mode 100644 index 00000000..6cd27fe7 --- /dev/null +++ b/src/ngScenario/output/Xml.js @@ -0,0 +1,51 @@ +'use strict'; + +/** + * Generates XML output into a context. + */ +angular.scenario.output('xml', function(context, runner, model) { + var $ = function(args) {return new context.init(args);}; + model.on('RunnerEnd', function() { + var scenario = $('<scenario></scenario>'); + context.append(scenario); + serializeXml(scenario, model.value); + }); + + /** + * Convert the tree into XML. + * + * @param {Object} context jQuery context to add the XML to. + * @param {Object} tree node to serialize + */ + function serializeXml(context, tree) { + angular.forEach(tree.children, function(child) { + var describeContext = $('<describe></describe>'); + describeContext.attr('id', child.id); + describeContext.attr('name', child.name); + context.append(describeContext); + serializeXml(describeContext, child); + }); + var its = $('<its></its>'); + context.append(its); + angular.forEach(tree.specs, function(spec) { + var it = $('<it></it>'); + it.attr('id', spec.id); + it.attr('name', spec.name); + it.attr('duration', spec.duration); + it.attr('status', spec.status); + its.append(it); + angular.forEach(spec.steps, function(step) { + var stepContext = $('<step></step>'); + stepContext.attr('name', step.name); + stepContext.attr('duration', step.duration); + stepContext.attr('status', step.status); + it.append(stepContext); + if (step.error) { + var error = $('<error></error>'); + stepContext.append(error); + error.text(formatException(stepContext.error)); + } + }); + }); + } +}); |
