diff options
Diffstat (limited to 'packages/astro-rss/test/test-utils.js')
-rw-r--r-- | packages/astro-rss/test/test-utils.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/packages/astro-rss/test/test-utils.js b/packages/astro-rss/test/test-utils.js index 4f0340333..dcc57df21 100644 --- a/packages/astro-rss/test/test-utils.js +++ b/packages/astro-rss/test/test-utils.js @@ -1,3 +1,5 @@ +import xml2js from 'xml2js'; + export const title = 'My RSS feed'; export const description = 'This sure is a nice RSS feed'; export const site = 'https://example.com'; @@ -45,3 +47,20 @@ export const web1FeedItemWithAllData = { type: 'audio/mpeg', }, }; + +const parser = new xml2js.Parser({ trim: true }); + +/** + * + * Utility function to parse an XML string into an object using `xml2js`. + * + * @param {string} xmlString - Stringified XML to parse. + * @return {{ err: Error, result: any }} Represents an option containing the parsed XML string or an Error. + */ +export function parseXmlString(xmlString) { + let res; + parser.parseString(xmlString, (err, result) => { + res = { err, result }; + }); + return res; +} |