fix: prevent preview-tests race condition (#39286)

This commit is contained in:
Oliver Eyton-Williams
2020-07-20 17:33:56 +02:00
committed by GitHub
parent fbdba9edb1
commit de55527693

View File

@ -40,14 +40,23 @@ import {
// How long before bailing out of a preview.
const previewTimeout = 2500;
let previewTask;
export function* executeCancellableChallengeSaga() {
if (previewTask) {
yield cancel(previewTask);
}
const task = yield fork(executeChallengeSaga);
previewTask = yield fork(previewChallengeSaga, { flushLogs: false });
yield take(types.cancelTests);
yield cancel(task);
}
export function* executeCancellablePreviewSaga() {
previewTask = yield fork(previewChallengeSaga);
}
export function* executeChallengeSaga() {
const isBuildEnabled = yield select(isBuildEnabledSelector);
if (!isBuildEnabled) {
@ -157,7 +166,7 @@ function* executeTests(testRunner, tests, testTimeout = 5000) {
}
// updates preview frame and the fcc console.
function* previewChallengeSaga() {
function* previewChallengeSaga({ flushLogs = true } = {}) {
yield delay(700);
const isBuildEnabled = yield select(isBuildEnabledSelector);
@ -169,8 +178,10 @@ function* previewChallengeSaga() {
const proxyLogger = args => logProxy.put(args);
try {
if (flushLogs) {
yield put(initLogs());
yield put(initConsole(''));
}
yield fork(takeEveryConsole, logProxy);
const challengeData = yield select(challengeDataSelector);
@ -212,7 +223,7 @@ export function createExecuteChallengeSaga(types) {
types.challengeMounted,
types.resetChallenge
],
previewChallengeSaga
executeCancellablePreviewSaga
)
];
}