FIX: Don't load JS via SCRIPT tag in QUnit mode

This commit is contained in:
Robin Ward 2017-05-31 15:31:24 -04:00
parent e22d88c91d
commit e66fa82f3a
3 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,8 @@
import loadScript from 'discourse/lib/load-script';
import { observes } from 'ember-addons/ember-computed-decorators';
const LOAD_ASYNC = !Ember.Test;
export default Ember.Component.extend({
mode: 'css',
classNames: ['ace-wrapper'],
@ -23,7 +25,7 @@ export default Ember.Component.extend({
@observes('mode')
modeChanged() {
if (this._editor && !this._skipContentChangeEvent) {
if (LOAD_ASYNC && this._editor && !this._skipContentChangeEvent) {
this._editor.getSession().setMode("ace/mode/" + this.get('mode'));
}
},
@ -56,10 +58,14 @@ export default Ember.Component.extend({
if (!this.element || this.isDestroying || this.isDestroyed) { return; }
const editor = loadedAce.edit(this.$('.ace')[0]);
editor.setTheme("ace/theme/chrome");
if (LOAD_ASYNC) {
editor.setTheme("ace/theme/chrome");
}
editor.setShowPrintMargin(false);
editor.setOptions({fontSize: "14px"});
editor.getSession().setMode("ace/mode/" + this.get('mode'));
if (LOAD_ASYNC) {
editor.getSession().setMode("ace/mode/" + this.get('mode'));
}
editor.on('change', () => {
this._skipContentChangeEvent = true;
this.set('content', editor.getSession().getValue());

View File

@ -35,6 +35,11 @@ export default function loadScript(url, opts) {
opts = opts || {};
$('script').each((i, tag) => {
_loaded[tag.getAttribute('src')] = true;
});
return new Ember.RSVP.Promise(function(resolve) {
url = Discourse.getURL(url);
@ -42,7 +47,7 @@ export default function loadScript(url, opts) {
if (_loaded[url]) { return resolve(); }
if (_loading[url]) { return _loading[url].then(resolve);}
var done;
let done;
_loading[url] = new Ember.RSVP.Promise(function(_done){
done = _done;
});
@ -60,7 +65,7 @@ export default function loadScript(url, opts) {
resolve();
};
var cdnUrl = url;
let cdnUrl = url;
// Scripts should always load from CDN
// CSS is type text, to accept it from a CDN we would need to handle CORS
@ -72,6 +77,9 @@ export default function loadScript(url, opts) {
// to dynamically load more JS. In that case, add the `scriptTag: true`
// option.
if (opts.scriptTag) {
if (Ember.Test) {
throw `In test mode scripts cannot be loaded async ${cdnUrl}`;
}
loadWithTag(cdnUrl, cb);
} else {
ajax({url: cdnUrl, dataType: opts.css ? "text": "script", cache: true}).then(cb);

View File

@ -48,6 +48,7 @@ window.MessageBus.stop();
// Trick JSHint into allow document.write
var d = document;
d.write('<script src="/javascripts/ace/ace.js"></script>');
d.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
d.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');