test-utils.js 923 B

1234567891011121314151617181920212223242526272829
  1. import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
  2. import * as xml2js from 'xml2js';
  3. /**
  4. * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
  5. */
  6. export function loadFixture(inlineConfig) {
  7. if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }");
  8. // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath
  9. // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test`
  10. return baseLoadFixture({
  11. ...inlineConfig,
  12. root: new URL(inlineConfig.root, import.meta.url).toString(),
  13. });
  14. }
  15. export function readXML(fileOrPromise) {
  16. const parseString = xml2js.parseString;
  17. return Promise.resolve(fileOrPromise).then((xml) => {
  18. return new Promise((resolve, reject) => {
  19. parseString(xml, function (err, result) {
  20. if (err) return reject(err);
  21. resolve(result);
  22. });
  23. });
  24. });
  25. }