Merge pull request #16 from Bouncey/feat/backendTests
Add backend tests
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
5f0068e9c8
commit
fa68757553
@ -115,6 +115,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
|||||||
component: views[viewTypes[challengeType]],
|
component: views[viewTypes[challengeType]],
|
||||||
context: {
|
context: {
|
||||||
challengeMeta: {
|
challengeMeta: {
|
||||||
|
challengeType,
|
||||||
template,
|
template,
|
||||||
required,
|
required,
|
||||||
nextChallengePath,
|
nextChallengePath,
|
||||||
|
@ -14,7 +14,8 @@ import {
|
|||||||
challengeTestsSelector,
|
challengeTestsSelector,
|
||||||
consoleOutputSelector,
|
consoleOutputSelector,
|
||||||
initTests,
|
initTests,
|
||||||
updateChallengeMeta
|
updateChallengeMeta,
|
||||||
|
backendNS
|
||||||
} from '../redux';
|
} from '../redux';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -72,12 +73,7 @@ const options = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class BackEnd extends PureComponent {
|
export class BackEnd extends PureComponent {
|
||||||
constructor(...props) {
|
componentDidMount() {
|
||||||
super(...props);
|
|
||||||
|
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
const {
|
const {
|
||||||
initTests,
|
initTests,
|
||||||
updateChallengeMeta,
|
updateChallengeMeta,
|
||||||
@ -101,18 +97,17 @@ export class BackEnd extends PureComponent {
|
|||||||
updateChallengeMeta(challengeMeta);
|
updateChallengeMeta(challengeMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleSubmit(values) {
|
|
||||||
console.log('backend', values);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
data: { challengeNode: { fields: { blockName }, title, description } },
|
data: { challengeNode: { fields: { blockName }, title, description } },
|
||||||
output,
|
output,
|
||||||
tests,
|
tests,
|
||||||
submitting
|
submitting,
|
||||||
|
executeChallenge
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
// TODO: Should be tied to user.isSigned
|
||||||
const buttonCopy = submitting
|
const buttonCopy = submitting
|
||||||
? 'Submit and go to my next challenge'
|
? 'Submit and go to my next challenge'
|
||||||
: "I've completed this challenge";
|
: "I've completed this challenge";
|
||||||
@ -128,9 +123,9 @@ export class BackEnd extends PureComponent {
|
|||||||
<Form
|
<Form
|
||||||
buttonText={buttonCopy + '(Ctrl + Enter)'}
|
buttonText={buttonCopy + '(Ctrl + Enter)'}
|
||||||
formFields={formFields}
|
formFields={formFields}
|
||||||
id='backend-form'
|
id={backendNS}
|
||||||
options={options}
|
options={options}
|
||||||
submit={this.handleSubmit}
|
submit={executeChallenge}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
|
@ -21,9 +21,7 @@ import ProjectForm from './ProjectForm';
|
|||||||
// signInLoadingSelector,
|
// signInLoadingSelector,
|
||||||
// challengeSelector
|
// challengeSelector
|
||||||
// } from '../../../../redux';
|
// } from '../../../../redux';
|
||||||
import { challengeTypes } from '../../../../utils/challengeTypes';
|
import { frontEndProject } from '../../../../utils/challengeTypes';
|
||||||
|
|
||||||
const { frontEndProject } = challengeTypes;
|
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
challengeType: PropTypes.number,
|
challengeType: PropTypes.number,
|
||||||
|
@ -16,6 +16,7 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
types,
|
types,
|
||||||
|
challengeMetaSelector,
|
||||||
challengeTestsSelector,
|
challengeTestsSelector,
|
||||||
initConsole,
|
initConsole,
|
||||||
updateConsole,
|
updateConsole,
|
||||||
@ -23,13 +24,15 @@ import {
|
|||||||
updateTests,
|
updateTests,
|
||||||
disableJSOnError
|
disableJSOnError
|
||||||
} from './';
|
} from './';
|
||||||
import { buildFromFiles } from '../utils/build';
|
import { buildFromFiles, buildBackendChallenge } from '../utils/build';
|
||||||
import {
|
import {
|
||||||
runTestsInTestFrame,
|
runTestsInTestFrame,
|
||||||
createTestFramer,
|
createTestFramer,
|
||||||
createMainFramer
|
createMainFramer
|
||||||
} from '../utils/frame.js';
|
} from '../utils/frame.js';
|
||||||
|
|
||||||
|
import { backend } from '../../../../utils/challengeTypes';
|
||||||
|
|
||||||
const executeDebounceTimeout = 750;
|
const executeDebounceTimeout = 750;
|
||||||
|
|
||||||
function updateMainEpic(actions, { getState }, { document }) {
|
function updateMainEpic(actions, { getState }, { document }) {
|
||||||
@ -90,14 +93,14 @@ function executeChallengeEpic(action$, { getState }, { document }) {
|
|||||||
// .filter(() => !codeLockedSelector(getState()))
|
// .filter(() => !codeLockedSelector(getState()))
|
||||||
switchMap(() => {
|
switchMap(() => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
// const { challengeType } = challengeSelector(state);
|
const { challengeType } = challengeMetaSelector(state);
|
||||||
// if (challengeType === backend) {
|
if (challengeType === backend) {
|
||||||
// return buildBackendChallenge(state)
|
return buildBackendChallenge(state)
|
||||||
// .do(frameTests)
|
.do(frameTests)
|
||||||
// .ignoreElements()
|
.ignoreElements()
|
||||||
// .startWith(initOutput('// running test'))
|
.startWith(initConsole('// running test'))
|
||||||
// .catch(createErrorObservable);
|
.catch(err => disableJSOnError(err));
|
||||||
// }
|
}
|
||||||
return buildFromFiles(state, false)
|
return buildFromFiles(state, false)
|
||||||
.do(frameTests)
|
.do(frameTests)
|
||||||
.ignoreElements()
|
.ignoreElements()
|
||||||
|
@ -8,6 +8,7 @@ import executeChallengeEpic from './execute-challenge-epic';
|
|||||||
import codeLockEpic from './code-lock-epic';
|
import codeLockEpic from './code-lock-epic';
|
||||||
|
|
||||||
const ns = 'challenge';
|
const ns = 'challenge';
|
||||||
|
export const backendNS = 'backendChallenge';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
challengeFiles: {},
|
challengeFiles: {},
|
||||||
@ -95,6 +96,7 @@ export const checkChallenge = createAction(types.checkChallenge);
|
|||||||
export const executeChallenge = createAction(types.executeChallenge);
|
export const executeChallenge = createAction(types.executeChallenge);
|
||||||
export const submitChallenge = createAction(types.submitChallenge);
|
export const submitChallenge = createAction(types.submitChallenge);
|
||||||
|
|
||||||
|
export const backendFormValuesSelector = state => state.form[backendNS];
|
||||||
export const challengeFilesSelector = state => state[ns].challengeFiles;
|
export const challengeFilesSelector = state => state[ns].challengeFiles;
|
||||||
export const challengeMetaSelector = state => state[ns].challengeMeta;
|
export const challengeMetaSelector = state => state[ns].challengeMeta;
|
||||||
export const challengeTestsSelector = state => state[ns].challengeTests;
|
export const challengeTestsSelector = state => state[ns].challengeTests;
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
|
import { combineLatest } from 'rxjs/observable/combineLatest';
|
||||||
|
import { map } from 'rxjs/operators/map';
|
||||||
import identity from 'lodash/identity';
|
import identity from 'lodash/identity';
|
||||||
|
|
||||||
// import { fetchScript } from './fetch-and-cache.js';
|
import { fetchScript } from './fetch-and-cache.js';
|
||||||
import throwers from '../rechallenge/throwers';
|
import throwers from '../rechallenge/throwers';
|
||||||
import {
|
import {
|
||||||
challengeFilesSelector,
|
challengeFilesSelector,
|
||||||
isJSEnabledSelector,
|
isJSEnabledSelector,
|
||||||
challengeMetaSelector,
|
challengeMetaSelector,
|
||||||
disableJSOnError
|
disableJSOnError,
|
||||||
|
backendFormValuesSelector
|
||||||
} from '../redux';
|
} from '../redux';
|
||||||
import {
|
import {
|
||||||
applyTransformers,
|
applyTransformers,
|
||||||
@ -19,11 +22,11 @@ import { createFileStream, pipe } from './polyvinyl';
|
|||||||
const jQuery = {
|
const jQuery = {
|
||||||
src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'
|
src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'
|
||||||
};
|
};
|
||||||
// const frameRunner = {
|
const frameRunner = {
|
||||||
// src: '/js/frame-runner.js',
|
src: '/js/frame-runner.js',
|
||||||
// crossDomain: false,
|
crossDomain: false,
|
||||||
// cacheBreaker: true
|
cacheBreaker: true
|
||||||
// };
|
};
|
||||||
const globalRequires = [
|
const globalRequires = [
|
||||||
{
|
{
|
||||||
link:
|
link:
|
||||||
@ -56,14 +59,16 @@ export function buildFromFiles(state, shouldProxyConsole) {
|
|||||||
.catch(err => disableJSOnError(err));
|
.catch(err => disableJSOnError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
// export function buildBackendChallenge(state) {
|
export function buildBackendChallenge(state) {
|
||||||
// const { solution: url } = backendFormValuesSelector(state);
|
const { solution: { value: url } } = backendFormValuesSelector(state);
|
||||||
// return Observable.combineLatest(
|
return combineLatest(
|
||||||
// fetchScript(frameRunner),
|
fetchScript(frameRunner),
|
||||||
// fetchScript(jQuery)
|
fetchScript(jQuery)
|
||||||
// ).map(([frameRunner, jQuery]) => ({
|
).pipe(
|
||||||
// build: jQuery + frameRunner,
|
map(([frameRunner, jQuery]) => ({
|
||||||
// sources: { url },
|
build: jQuery + frameRunner,
|
||||||
// checkChallengePayload: { solution: url }
|
sources: { url },
|
||||||
// }));
|
checkChallengePayload: { solution: url }
|
||||||
// }
|
})
|
||||||
|
));
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { ajax$ } from '../utils/ajax-stream';
|
import { ajax$ } from './ajax-stream';
|
||||||
|
|
||||||
// value used to break browser ajax caching
|
// value used to break browser ajax caching
|
||||||
const cacheBreakerValue = Math.random();
|
const cacheBreakerValue = Math.random();
|
||||||
|
@ -10,6 +10,10 @@ const step = 7;
|
|||||||
const quiz = 8;
|
const quiz = 8;
|
||||||
const invalid = 9;
|
const invalid = 9;
|
||||||
|
|
||||||
|
// individual exports
|
||||||
|
exports.backend = backend;
|
||||||
|
exports.frontEndProject = frontEndProject;
|
||||||
|
|
||||||
exports.challengeTypes = {
|
exports.challengeTypes = {
|
||||||
html,
|
html,
|
||||||
js,
|
js,
|
||||||
|
Reference in New Issue
Block a user