Fix test-challenges to use code/editor.getValue
Also filters challenges with empty string testspull/18182/head
parent
b0e131a848
commit
b6622e75fc
|
@ -51,8 +51,23 @@ function fillAssert(t) {
|
||||||
return assert;
|
return assert;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTest({ title, tests = [], solutions = [] }) {
|
function createTest({
|
||||||
|
title,
|
||||||
|
tests = [],
|
||||||
|
solutions = [],
|
||||||
|
head = '',
|
||||||
|
tail = ''
|
||||||
|
}) {
|
||||||
|
solutions = solutions.filter(solution => !!solution);
|
||||||
|
tests = tests.filter(test => !!test);
|
||||||
const plan = tests.length;
|
const plan = tests.length;
|
||||||
|
if (!plan) {
|
||||||
|
return Observable.just({
|
||||||
|
title,
|
||||||
|
type: 'missing'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return Observable.fromCallback(tape)(title)
|
return Observable.fromCallback(tape)(title)
|
||||||
.doOnNext(t => solutions.length ? t.plan(plan) : t.end())
|
.doOnNext(t => solutions.length ? t.plan(plan) : t.end())
|
||||||
.flatMap(t => {
|
.flatMap(t => {
|
||||||
|
@ -64,16 +79,19 @@ function createTest({ title, tests = [], solutions = [] }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return Observable.just(t)
|
return Observable.just(t)
|
||||||
.map(fillAssert)
|
.map(fillAssert)
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
// assert is used within the eval
|
// assert is used within the eval
|
||||||
.doOnNext(assert => {
|
.doOnNext(assert => {
|
||||||
/* eslint-enable no-unused-vars */
|
|
||||||
solutions.forEach(solution => {
|
solutions.forEach(solution => {
|
||||||
tests.forEach(test => {
|
tests.forEach(test => {
|
||||||
|
const code = head + solution + tail;
|
||||||
|
const editor = { getValue() { return code; } };
|
||||||
|
/* eslint-enable no-unused-vars */
|
||||||
try {
|
try {
|
||||||
eval(solution + ';;' + test);
|
(() => { return eval(solution + ';;' + test); })();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
t.fail(e);
|
t.fail(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue