Preprocessor for converting XML files into JavaScript DOM objects.
Just run:
npm install karma-xml2js-preprocessor --save-dev
This is the default configuration:
// karma.conf.js
module.exports = function(config) {
config.set({
preprocessors: {
'**/*.xml': ['xml2js']
},
files: [
'**/*.xml',
'*.js'
]
});
};
This preprocessor converts XML files into JS DOM objects and publishes them in the global window.__xml__
.
For instance this doc.xml
...
<?xml version="1.0" encoding="UTF-8"?>
<tag>content</tag>
... will be served as doc.xml.js
:
window.__xml__ = window.__xml__ || {};
window.__xml__['doc.xml'] = /* DOM object obtained by parsing the content of doc.xml */;