feat(client): execute backend challenge saga

This commit is contained in:
Valeriy S
2018-12-10 10:00:26 +03:00
committed by Stuart Taylor
parent 6d7744646d
commit c43dfe1eb7
2 changed files with 35 additions and 12 deletions

View File

@ -20,7 +20,11 @@ import {
challengeFilesSelector
} from './';
import { buildJSFromFiles, buildFromFiles } from '../utils/build';
import {
buildJSFromFiles,
buildFromFiles,
buildBackendChallenge
} from '../utils/build';
import { challengeTypes } from '../../../../utils/challengeTypes';
@ -39,11 +43,6 @@ function* ExecuteChallengeSaga() {
const { js, bonfire, backend } = challengeTypes;
const { challengeType } = yield select(challengeMetaSelector);
// TODO: ExecuteBackendChallengeSaga
if (challengeType === backend) {
return;
}
yield put(initLogs());
yield put(initConsole('// running tests'));
@ -54,7 +53,7 @@ function* ExecuteChallengeSaga() {
testResults = yield ExecuteJSChallengeSaga();
break;
case backend:
// yield ExecuteBackendChallengeSaga();
testResults = yield ExecuteBackendChallengeSaga();
break;
default:
testResults = yield ExecuteDOMChallengeSaga();
@ -119,6 +118,32 @@ function* ExecuteDOMChallengeSaga() {
return testResults;
}
// TODO: use a web worker
function* ExecuteBackendChallengeSaga() {
const state = yield select();
const ctx = yield call(buildBackendChallenge, state);
const consoleProxy = yield channel();
yield call(createTestFrame, state, ctx, consoleProxy);
const testResults = yield call(executeTests, {
testRunner: {
execute({ script }, testTimeout) {
return Promise.race([
runTestInTestFrame(document, script),
new Promise((_, reject) =>
setTimeout(() => reject('timeout'), testTimeout)
)
]);
},
killWorker() {}
}
});
consoleProxy.close();
return testResults;
}
function* updateMainSaga() {
try {
const { html, modern } = challengeTypes;

View File

@ -1,4 +1,3 @@
import { of } from 'rxjs';
import { flow } from 'lodash';
import { throwers } from '../rechallenge/throwers';
@ -111,9 +110,8 @@ export function buildBackendChallenge(state) {
const {
solution: { value: url }
} = backendFormValuesSelector(state);
return of({
return {
build: frameRunner,
sources: { url },
checkChallengePayload: { solution: url }
});
sources: { url }
};
}