diff --git a/client/commonFramework/add-faux-stream.js b/client/commonFramework/add-faux-stream.js
index c25f69f75b..17a57e212c 100644
--- a/client/commonFramework/add-faux-stream.js
+++ b/client/commonFramework/add-faux-stream.js
@@ -1,35 +1,22 @@
window.common = (function(global) {
const {
- $,
- Rx: { Observable, Disposable },
common = { init: [] }
} = global;
- function getFaux() {
- return new Observable(function(observer) {
- const jqXHR = $.get('/js/faux.js')
- .success(data => observer.onNext(data))
- .fail(e => observer.onError(e))
- .always(() => observer.onCompleted());
+ const faux$ = common.getScriptContent$('/js/faux.js').shareReplay();
- return new Disposable(() => {
- jqXHR.abort();
- });
- });
- }
-
- const faux$ = getFaux().shareReplay();
-
- common.safeHTMLRun = function safeHTMLRun(code) {
- if (!code.match(/\";
+ const iFrameScript$ =
+ common.getScriptContent$('/js/iFrameScripts.js').shareReplay();
+ // runPreviewTests$ should be set up in the preview window
+ common.runPreviewTests$ =
+ () => Observable.throw({ err: new Error('run preview not enabled') });
- common.updatePreview = function updatePreview(code = '', shouldTest = false) {
+ common.updatePreview$ = function updatePreview$(code = '') {
const previewFrame = document.getElementById('preview');
const preview = previewFrame.contentDocument ||
previewFrame.contentWindow.document;
if (!preview) {
- return code;
+ return Observable.just(code);
}
- preview.open();
- preview.write(libraryIncludes + code + (shouldTest ? iFrameScript : ''));
- preview.close();
- return code;
+ return iFrameScript$
+ .map(script => ``)
+ .doOnNext(script => {
+ preview.open();
+ preview.write(libraryIncludes + code + script);
+ preview.close();
+ })
+ .map(() => code);
};
return common;
diff --git a/client/iFrameScripts.js b/client/iFrameScripts.js
index 66cb8554ba..5fbf663a11 100644
--- a/client/iFrameScripts.js
+++ b/client/iFrameScripts.js
@@ -2,27 +2,36 @@
window.$ = parent.$;
window.$(function() {
var _ = parent._;
+ var Rx = parent.Rx;
var chai = parent.chai;
- var expect = chai.expect;
+ var assert = chai.assert;
var tests = parent.tests;
var common = parent.common;
- var editorValue = common.editor.getValue();
+ var code = common.editor.getValue();
var editor = common.editor;
- var userTests = common.tests.map(test => {
- var 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(/\)/, '');
- }
- });
+ 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 }));
+ };
+
});