chore: add test util for extracting island data

This commit is contained in:
Nate Moore 2023-08-15 12:57:02 -05:00
parent a037015a5a
commit f744d2bb76

View file

@ -242,6 +242,18 @@ export async function loadFixture(inlineConfig) {
};
}
/**
*
* @param {string} text
* @returns {{ componentUrl: string, componentExport: string, rendererUrl: string, opts: Record<string, unknown>, props: Record<string, unknown> }}
*/
export function getIslandDataFromScript(text) {
// Island script references `Astro` and `document` globals, so we need to mock them
const prelude = [`const Astro = { assign: (_, props) => props }`, `const document = {}`, ''].join(';')
// Yes, I know, `eval` is bad! But our data is embedded as JS on purpose.
return new Function([prelude, `return ${text}`].join(''))();
}
/**
* @param {string} [address]
*/