2016-05-20 19:42:26 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
var common = parent.__common;
|
2016-05-26 01:28:20 +00:00
|
|
|
var frameId = window.__frameId;
|
|
|
|
var frameReady = common[frameId + 'Ready$'] || { onNext() {} };
|
|
|
|
var Rx = document.Rx;
|
|
|
|
var chai = parent.chai;
|
|
|
|
var source = document.__source;
|
2016-05-20 19:42:26 +00:00
|
|
|
|
2016-05-26 01:28:20 +00:00
|
|
|
document.__getJsOutput = function getJsOutput() {
|
2016-05-20 19:42:26 +00:00
|
|
|
if (window.__err || !common.shouldRun()) {
|
|
|
|
return window.__err || 'source disabled';
|
|
|
|
}
|
|
|
|
let output;
|
|
|
|
try {
|
|
|
|
/* eslint-disable no-eval */
|
|
|
|
output = eval(source);
|
|
|
|
/* eslint-enable no-eval */
|
|
|
|
} catch (e) {
|
2016-05-28 00:11:25 +00:00
|
|
|
output = e.message + '\n' + e.stack;
|
2016-05-20 19:42:26 +00:00
|
|
|
window.__err = e;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
2016-05-26 01:28:20 +00:00
|
|
|
document.__runTests$ = function runTests$(tests = []) {
|
|
|
|
/* eslint-disable no-unused-vars */
|
2016-05-20 19:42:26 +00:00
|
|
|
const editor = { getValue() { return source; } };
|
2016-05-26 01:28:20 +00:00
|
|
|
const code = source;
|
|
|
|
/* eslint-enable no-unused-vars */
|
2016-05-20 19:42:26 +00:00
|
|
|
if (window.__err) {
|
|
|
|
return Rx.Observable.throw(window.__err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through the test one at a time
|
|
|
|
// on new stacks
|
|
|
|
return Rx.Observable.from(tests, null, null, Rx.Scheduler.default)
|
|
|
|
// add delay here for firefox to catch up
|
2016-05-26 01:28:20 +00:00
|
|
|
.delay(200)
|
|
|
|
/* eslint-disable no-unused-vars */
|
2016-05-20 19:42:26 +00:00
|
|
|
.map(({ text, testString }) => {
|
2016-05-26 01:28:20 +00:00
|
|
|
const assert = chai.assert;
|
|
|
|
/* eslint-enable no-unused-vars */
|
2016-05-20 19:42:26 +00:00
|
|
|
const newTest = { text, testString };
|
|
|
|
let test;
|
|
|
|
try {
|
|
|
|
/* eslint-disable no-eval */
|
|
|
|
test = eval(testString);
|
|
|
|
/* eslint-enable no-eval */
|
|
|
|
if (typeof test === 'function') {
|
|
|
|
// maybe sync/promise/observable
|
|
|
|
if (test.length === 0) {
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
// callback test
|
|
|
|
if (test.length === 1) {
|
|
|
|
console.log('callback test');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2016-05-26 01:28:20 +00:00
|
|
|
newTest.err = e.message + '\n' + e.stack;
|
|
|
|
}
|
|
|
|
if (!newTest.err) {
|
|
|
|
newTest.pass = true;
|
2016-05-20 19:42:26 +00:00
|
|
|
}
|
|
|
|
return newTest;
|
|
|
|
})
|
|
|
|
// gather tests back into an array
|
|
|
|
.toArray();
|
|
|
|
};
|
|
|
|
|
2016-05-28 00:11:25 +00:00
|
|
|
// notify that the window methods are ready to run
|
2016-05-26 01:28:20 +00:00
|
|
|
frameReady.onNext(null);
|
2016-05-20 19:42:26 +00:00
|
|
|
});
|