chore: add test util for extracting island data
This commit is contained in:
parent
a037015a5a
commit
f744d2bb76
1 changed files with 12 additions and 0 deletions
|
@ -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]
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue