fix: samples function did not work in tests

This commit is contained in:
Felix Roos 2022-11-06 00:44:23 +01:00
parent da8e00eb4e
commit 866277510e
2 changed files with 142 additions and 0 deletions

View file

@ -108,6 +108,10 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '') => {
const [_, path] = sampleMap.split('github:');
sampleMap = `https://raw.githubusercontent.com/${path}/strudel.json`;
}
if (typeof fetch !== 'function') {
// not a browser
return;
}
const base = sampleMap.split('/').slice(0, -1).join('/');
return fetch(sampleMap)
.then((res) => res.json())