2015-11-04 20:37:25 +00:00
|
|
|
/* eslint-disable no-undef, no-unused-vars, no-native-reassign */
|
2015-11-30 22:27:39 +00:00
|
|
|
// the $ on the iframe window object is the same
|
|
|
|
// as the one used on the main site, but
|
|
|
|
// uses the iframe document as the context
|
|
|
|
window.$(document).ready(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;
|
2015-05-28 12:26:25 +00:00
|
|
|
var tests = parent.tests;
|
2015-11-13 19:10:23 +00:00
|
|
|
var common = parent.common;
|
2015-11-30 22:27:39 +00:00
|
|
|
|
2015-12-02 01:38:48 +00:00
|
|
|
window.loopProtect.hit = function(line) {
|
|
|
|
window.__err = new Error(
|
|
|
|
'Potential infinite loop at line ' + line
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2015-11-30 22:27:39 +00:00
|
|
|
common.getJsOutput = function evalJs(code = '') {
|
|
|
|
let output;
|
|
|
|
try {
|
|
|
|
/* eslint-disable no-eval */
|
|
|
|
output = eval(code);
|
|
|
|
/* eslint-enable no-eval */
|
|
|
|
} catch (e) {
|
|
|
|
window.__err = e;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
};
|
2015-05-28 12:26:25 +00:00
|
|
|
|
2015-11-23 03:42:53 +00:00
|
|
|
common.runPreviewTests$ =
|
2015-11-30 22:27:39 +00:00
|
|
|
function runPreviewTests$({
|
|
|
|
tests = [],
|
|
|
|
originalCode,
|
|
|
|
...rest
|
|
|
|
}) {
|
|
|
|
const code = originalCode;
|
|
|
|
const editor = { getValue() { return originalCode; } };
|
|
|
|
if (window.__err) {
|
|
|
|
return Rx.Observable.throw(window.__err);
|
|
|
|
}
|
|
|
|
|
2015-12-02 19:19:15 +00:00
|
|
|
return Rx.Observable.from(tests, null, null, Rx.Scheduler.default)
|
|
|
|
.delay(100)
|
2015-11-23 03:42:53 +00:00
|
|
|
.map(test => {
|
|
|
|
const userTest = {};
|
2015-11-30 22:27:39 +00:00
|
|
|
common.appendToOutputDisplay('');
|
2015-11-23 03:42:53 +00:00
|
|
|
try {
|
|
|
|
/* eslint-disable no-eval */
|
|
|
|
eval(test);
|
|
|
|
/* eslint-enable no-eval */
|
|
|
|
} catch (e) {
|
|
|
|
userTest.err = e.message.split(':').shift();
|
|
|
|
} finally {
|
2015-12-02 07:24:03 +00:00
|
|
|
if (!test.match(/message: /g)) {
|
|
|
|
userTest.text = 'message: ' + test
|
|
|
|
.split(',')
|
|
|
|
.pop()
|
|
|
|
.replace(/\'/g, '')
|
|
|
|
.replace(/\)/, '');
|
|
|
|
} else {
|
|
|
|
userTest.text = test;
|
|
|
|
}
|
2015-11-23 03:42:53 +00:00
|
|
|
}
|
|
|
|
return userTest;
|
|
|
|
})
|
|
|
|
.toArray()
|
2015-11-30 22:27:39 +00:00
|
|
|
.map(tests => ({ ...rest, tests, originalCode }));
|
2015-11-23 03:42:53 +00:00
|
|
|
};
|
|
|
|
|
2015-12-01 16:01:51 +00:00
|
|
|
// now that the runPreviewTest$ is defined
|
|
|
|
// we set the subject to true
|
|
|
|
// this will let the updatePreview
|
|
|
|
// script now that we are ready.
|
|
|
|
common.previewReady$.onNext(true);
|
2015-11-13 19:10:23 +00:00
|
|
|
});
|