fix(test): simplify test runner
This commit is contained in:
parent
bc3d88605c
commit
98ba33e7a3
@ -231,14 +231,6 @@ const DeepFreeze = o => {
|
|||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
|
|
||||||
function isPromise(value) {
|
|
||||||
return (
|
|
||||||
value &&
|
|
||||||
typeof value.subscribe !== 'function' &&
|
|
||||||
typeof value.then === 'function'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformSass(solution) {
|
function transformSass(solution) {
|
||||||
const fragment = JSDOM.fragment(`<div>${solution}</div>`);
|
const fragment = JSDOM.fragment(`<div>${solution}</div>`);
|
||||||
const styleTags = fragment.querySelectorAll('style[type="text/sass"]');
|
const styleTags = fragment.querySelectorAll('style[type="text/sass"]');
|
||||||
@ -347,19 +339,11 @@ async function runTestInBrowser(code, testString) {
|
|||||||
};
|
};
|
||||||
/* eslint-enable no-unused-vars */
|
/* eslint-enable no-unused-vars */
|
||||||
|
|
||||||
const isPromise = value =>
|
|
||||||
value &&
|
|
||||||
typeof value.subscribe !== 'function' &&
|
|
||||||
typeof value.then === 'function';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-eval
|
// eslint-disable-next-line no-eval
|
||||||
const test = eval(testString);
|
const test = eval(testString);
|
||||||
if (typeof test === 'function') {
|
if (typeof test === 'function') {
|
||||||
const __result = test(() => code);
|
await test(() => code);
|
||||||
if (isPromise(__result)) {
|
|
||||||
await __result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
@ -518,7 +502,6 @@ async function runTestInJsdom(dom, testString, scriptString = '') {
|
|||||||
dom.window.assert = assert;
|
dom.window.assert = assert;
|
||||||
dom.window.DeepEqual = DeepEqual;
|
dom.window.DeepEqual = DeepEqual;
|
||||||
dom.window.DeepFreeze = DeepFreeze;
|
dom.window.DeepFreeze = DeepFreeze;
|
||||||
dom.window.isPromise = isPromise;
|
|
||||||
|
|
||||||
dom.window.__test = testString;
|
dom.window.__test = testString;
|
||||||
scriptString += `;
|
scriptString += `;
|
||||||
@ -527,10 +510,7 @@ async function runTestInJsdom(dom, testString, scriptString = '') {
|
|||||||
try {
|
try {
|
||||||
const testResult = eval(__test);
|
const testResult = eval(__test);
|
||||||
if (typeof testResult === 'function') {
|
if (typeof testResult === 'function') {
|
||||||
const __result = testResult(() => code);
|
await testResult(() => code);
|
||||||
if (isPromise(__result)) {
|
|
||||||
await __result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}catch (e) {
|
}catch (e) {
|
||||||
window.__error = e;
|
window.__error = e;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user