summaryrefslogtreecommitdiff
path: root/packages/astro-rss/test/test-utils.js
diff options
context:
space:
mode:
authorGravatar voxel!() <voxelmc@hotmail.com> 2024-02-04 11:58:44 -0800
committerGravatar GitHub <noreply@github.com> 2024-02-04 19:58:44 +0000
commit4260ecf1ff4ba38f5f068c642158f4cc1a4815e5 (patch)
tree86f3addcd8f3987f0ababe2e84b94fdbf9cc6300 /packages/astro-rss/test/test-utils.js
parent8b8f26fdf2af2a769f4846bdaaf4cf6b30f9e37c (diff)
downloadastro-4260ecf1ff4ba38f5f068c642158f4cc1a4815e5.tar.gz
astro-4260ecf1ff4ba38f5f068c642158f4cc1a4815e5.tar.zst
astro-4260ecf1ff4ba38f5f068c642158f4cc1a4815e5.zip
chore(`@astrojs/rss`): Migrate tests to `node:test` (#9939)
* Progressively add new tests (remove old later) * Finalize tests * Remove unused comments * Assert that errors are not present and add jsdocs to util function * Fix * Remove mocha deps
Diffstat (limited to 'packages/astro-rss/test/test-utils.js')
-rw-r--r--packages/astro-rss/test/test-utils.js19
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;
+}