fix(curriculum): prevent infinite test execution (#34297)
This commit is contained in:
parent
ac160308e7
commit
82ec250c75
@ -63,7 +63,7 @@ const jQueryScript = fs.readFileSync(
|
|||||||
));
|
));
|
||||||
|
|
||||||
describe('Check challenges tests', async function() {
|
describe('Check challenges tests', async function() {
|
||||||
this.timeout(200000);
|
this.timeout(5000);
|
||||||
|
|
||||||
allChallenges.forEach(challenge => {
|
allChallenges.forEach(challenge => {
|
||||||
describe(challenge.title || 'No title', async function() {
|
describe(challenge.title || 'No title', async function() {
|
||||||
@ -221,6 +221,10 @@ function isPromise(value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function timeout(milliseconds) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||||
|
}
|
||||||
|
|
||||||
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"]');
|
||||||
@ -317,7 +321,16 @@ A required file can not have both a src and a link: src = ${src}, link = ${link}
|
|||||||
</head>
|
</head>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
solution = transformSass(solution);
|
const sandbox = { solution, transformSass };
|
||||||
|
const context = vm.createContext(sandbox);
|
||||||
|
vm.runInContext(
|
||||||
|
'solution = transformSass(solution);',
|
||||||
|
context,
|
||||||
|
{
|
||||||
|
timeout: 2000
|
||||||
|
}
|
||||||
|
);
|
||||||
|
solution = sandbox.solution;
|
||||||
solution = replaceColorNames(solution);
|
solution = replaceColorNames(solution);
|
||||||
|
|
||||||
const dom = new JSDOM(`
|
const dom = new JSDOM(`
|
||||||
@ -331,7 +344,7 @@ A required file can not have both a src and a link: src = ${src}, link = ${link}
|
|||||||
`, options);
|
`, options);
|
||||||
|
|
||||||
if (links || challengeType === challengeTypes.modern) {
|
if (links || challengeType === challengeTypes.modern) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await timeout(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.window.code = code;
|
dom.window.code = code;
|
||||||
@ -483,7 +496,7 @@ async function runTestInJsdom(dom, testString, scriptString = '') {
|
|||||||
}
|
}
|
||||||
})();`;
|
})();`;
|
||||||
const script = new vm.Script(scriptString);
|
const script = new vm.Script(scriptString);
|
||||||
dom.runVMScript(script);
|
dom.runVMScript(script, { timeout: 5000 });
|
||||||
await dom.window.__result;
|
await dom.window.__result;
|
||||||
if (dom.window.__error) {
|
if (dom.window.__error) {
|
||||||
throw dom.window.__error;
|
throw dom.window.__error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user