freeCodeCamp/client/iFrameScripts.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-11-04 20:37:25 +00:00
/* eslint-disable no-undef, no-unused-vars, no-native-reassign */
window.__$ = parent.$;
window.__$(function() {
2015-11-13 19:10:23 +00:00
var _ = parent._;
2015-11-23 03:42:53 +00:00
var Rx = parent.Rx;
2015-11-13 19:10:23 +00:00
var chai = parent.chai;
2015-11-23 03:42:53 +00:00
var assert = chai.assert;
var tests = parent.tests;
2015-11-13 19:10:23 +00:00
var common = parent.common;
var editor = common.editor.getValue();
// change the context of $ so it uses the iFrame for testing
var $ = __$.proxy(__$.fn.find, __$(document));
2015-11-23 03:42:53 +00:00
common.runPreviewTests$ =
function runPreviewTests$({ tests = [], ...rest }) {
return Rx.Observable.from(tests)
.map(test => {
const userTest = {};
try {
/* eslint-disable no-eval */
eval(test);
/* eslint-enable no-eval */
} catch (e) {
userTest.err = e.message.split(':').shift();
} finally {
userTest.text = test
.split(',')
.pop()
.replace(/\'/g, '')
.replace(/\)/, '');
}
return userTest;
})
.toArray()
.map(tests => ({ ...rest, tests }));
};
2015-11-13 19:10:23 +00:00
});