feat(client): execute backend challenge saga
This commit is contained in:
@ -20,7 +20,11 @@ import {
|
|||||||
challengeFilesSelector
|
challengeFilesSelector
|
||||||
} from './';
|
} from './';
|
||||||
|
|
||||||
import { buildJSFromFiles, buildFromFiles } from '../utils/build';
|
import {
|
||||||
|
buildJSFromFiles,
|
||||||
|
buildFromFiles,
|
||||||
|
buildBackendChallenge
|
||||||
|
} from '../utils/build';
|
||||||
|
|
||||||
import { challengeTypes } from '../../../../utils/challengeTypes';
|
import { challengeTypes } from '../../../../utils/challengeTypes';
|
||||||
|
|
||||||
@ -39,11 +43,6 @@ function* ExecuteChallengeSaga() {
|
|||||||
const { js, bonfire, backend } = challengeTypes;
|
const { js, bonfire, backend } = challengeTypes;
|
||||||
const { challengeType } = yield select(challengeMetaSelector);
|
const { challengeType } = yield select(challengeMetaSelector);
|
||||||
|
|
||||||
// TODO: ExecuteBackendChallengeSaga
|
|
||||||
if (challengeType === backend) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
yield put(initLogs());
|
yield put(initLogs());
|
||||||
yield put(initConsole('// running tests'));
|
yield put(initConsole('// running tests'));
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ function* ExecuteChallengeSaga() {
|
|||||||
testResults = yield ExecuteJSChallengeSaga();
|
testResults = yield ExecuteJSChallengeSaga();
|
||||||
break;
|
break;
|
||||||
case backend:
|
case backend:
|
||||||
// yield ExecuteBackendChallengeSaga();
|
testResults = yield ExecuteBackendChallengeSaga();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
testResults = yield ExecuteDOMChallengeSaga();
|
testResults = yield ExecuteDOMChallengeSaga();
|
||||||
@ -119,6 +118,32 @@ function* ExecuteDOMChallengeSaga() {
|
|||||||
return testResults;
|
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() {
|
function* updateMainSaga() {
|
||||||
try {
|
try {
|
||||||
const { html, modern } = challengeTypes;
|
const { html, modern } = challengeTypes;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { of } from 'rxjs';
|
|
||||||
import { flow } from 'lodash';
|
import { flow } from 'lodash';
|
||||||
|
|
||||||
import { throwers } from '../rechallenge/throwers';
|
import { throwers } from '../rechallenge/throwers';
|
||||||
@ -111,9 +110,8 @@ export function buildBackendChallenge(state) {
|
|||||||
const {
|
const {
|
||||||
solution: { value: url }
|
solution: { value: url }
|
||||||
} = backendFormValuesSelector(state);
|
} = backendFormValuesSelector(state);
|
||||||
return of({
|
return {
|
||||||
build: frameRunner,
|
build: frameRunner,
|
||||||
sources: { url },
|
sources: { url }
|
||||||
checkChallengePayload: { solution: url }
|
};
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user