diff options
author | 2025-06-05 14:25:23 +0000 | |
---|---|---|
committer | 2025-06-05 14:25:23 +0000 | |
commit | e586d7d704d475afe3373a1de6ae20d504f79d6d (patch) | |
tree | 7e3fa24807cebd48a86bd40f866d792181191ee9 /packages/integrations/sitemap/test/test-utils.js | |
download | astro-latest.tar.gz astro-latest.tar.zst astro-latest.zip |
Sync from a8e1c0a7402940e0fc5beef669522b315052df1blatest
Diffstat (limited to 'packages/integrations/sitemap/test/test-utils.js')
-rw-r--r-- | packages/integrations/sitemap/test/test-utils.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/integrations/sitemap/test/test-utils.js b/packages/integrations/sitemap/test/test-utils.js new file mode 100644 index 000000000..74bba6a44 --- /dev/null +++ b/packages/integrations/sitemap/test/test-utils.js @@ -0,0 +1,29 @@ +import * as xml2js from 'xml2js'; +import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; + +/** + * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture + */ + +export function loadFixture(inlineConfig) { + if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); + + // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath + // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` + return baseLoadFixture({ + ...inlineConfig, + root: new URL(inlineConfig.root, import.meta.url).toString(), + }); +} + +export function readXML(fileOrPromise) { + const parseString = xml2js.parseString; + return Promise.resolve(fileOrPromise).then((xml) => { + return new Promise((resolve, reject) => { + parseString(xml, function (err, result) { + if (err) return reject(err); + resolve(result); + }); + }); + }); +} |