From d263ed4ed7fe2c992477889753c7ec8bc7305a27 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Wed, 9 Jan 2019 03:36:45 +0300 Subject: [PATCH] fix: use document from store context --- client/src/redux/createStore.js | 6 +++++- .../Challenges/redux/execute-challenge-saga.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client/src/redux/createStore.js b/client/src/redux/createStore.js index 83614fafeb..9c824d3c5e 100644 --- a/client/src/redux/createStore.js +++ b/client/src/redux/createStore.js @@ -11,7 +11,11 @@ import { isBrowser } from '../../utils'; const clientSide = isBrowser(); -const sagaMiddleware = createSagaMiddleware(); +const sagaMiddleware = createSagaMiddleware({ + context: { + document: clientSide ? document : {} + } +}); const epicMiddleware = createEpicMiddleware({ dependencies: { window: clientSide ? window : {}, diff --git a/client/src/templates/Challenges/redux/execute-challenge-saga.js b/client/src/templates/Challenges/redux/execute-challenge-saga.js index 45989a8a7f..0db235202b 100644 --- a/client/src/templates/Challenges/redux/execute-challenge-saga.js +++ b/client/src/templates/Challenges/redux/execute-challenge-saga.js @@ -4,7 +4,8 @@ import { call, takeLatest, takeEvery, - fork + fork, + getContext } from 'redux-saga/effects'; import { delay, channel } from 'redux-saga'; @@ -99,15 +100,16 @@ function* executeJSChallengeSaga(state, proxyLogger) { } } -function createTestFrame(ctx, proxyLogger) { +function createTestFrame(document, ctx, proxyLogger) { return new Promise(resolve => createTestFramer(document, resolve, proxyLogger)(ctx) ); } function* executeDOMChallengeSaga(state, proxyLogger) { + const document = yield getContext('document'); const ctx = yield call(buildDOMChallenge, state); - yield call(createTestFrame, ctx, proxyLogger); + yield call(createTestFrame, document, ctx, proxyLogger); // wait for a code execution on a "ready" event in jQuery challenges yield delay(100); @@ -118,8 +120,9 @@ function* executeDOMChallengeSaga(state, proxyLogger) { // TODO: use a web worker function* executeBackendChallengeSaga(state, proxyLogger) { + const document = yield getContext('document'); const ctx = yield call(buildBackendChallenge, state); - yield call(createTestFrame, ctx, proxyLogger); + yield call(createTestFrame, document, ctx, proxyLogger); return yield call(executeTests, (testString, testTimeout) => runTestInTestFrame(document, testString, testTimeout) @@ -166,6 +169,7 @@ function* updateMainSaga() { } const state = yield select(); const ctx = yield call(buildDOMChallenge, state); + const document = yield getContext('document'); const frameMain = yield call(createMainFramer, document); yield call(frameMain, ctx); } catch (err) {