mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-08 12:04:29 -05:00
fix(client): ensure dom ready before testing (#39073)
jQuery challenges can fail seemingly at random. These changes should prevent the race condition between a user's $( document ).ready() and test evalution.
This commit is contained in:
committed by
GitHub
parent
3fed51a3df
commit
daed7ad5dd
@@ -59,8 +59,22 @@ async function initTestFrame(e = {}) {
|
||||
// eval test string to actual JavaScript
|
||||
// This return can be a function
|
||||
// i.e. function() { assert(true, 'happy coding'); }
|
||||
// eslint-disable-next-line no-eval
|
||||
const test = eval(testString);
|
||||
const testPromise = new Promise((resolve, reject) =>
|
||||
// To avoid race conditions, we have to run the test in a final
|
||||
// document ready:
|
||||
$(() => {
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
const test = eval(testString);
|
||||
resolve({ test });
|
||||
} catch (err) {
|
||||
reject({ err });
|
||||
}
|
||||
})
|
||||
);
|
||||
const { test, err } = await testPromise;
|
||||
if (err) throw err;
|
||||
|
||||
if (typeof test === 'function') {
|
||||
await test(e.getUserInput);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user