DEV: Import ember ENV instead of Ember.testing (#8305)

This commit is contained in:
Mark VanLandingham 2019-11-07 11:20:35 -06:00 committed by GitHub
parent 60a235d128
commit 9ffdbf912f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 75 additions and 37 deletions

View File

@ -9,6 +9,7 @@ import { outputExportResult } from "discourse/lib/export-result";
import { isNumeric } from "discourse/lib/utilities";
import { SCHEMA_VERSION, default as Report } from "admin/models/report";
import computed from "ember-addons/ember-computed-decorators";
import ENV from "discourse-common/config/environment";
const TABLE_OPTIONS = {
perPage: 8,
@ -162,8 +163,8 @@ export default Component.extend({
let reportKey = "reports:";
reportKey += [
dataSourceName,
Ember.testing ? "start" : startDate.replace(/-/g, ""),
Ember.testing ? "end" : endDate.replace(/-/g, ""),
ENV.environment === "test" ? "start" : startDate.replace(/-/g, ""),
ENV.environment === "test" ? "end" : endDate.replace(/-/g, ""),
"[:prev_period]",
this.get("reportOptions.table.limit"),
customFilters

View File

@ -7,6 +7,7 @@ import {
} from "ember-addons/ember-computed-decorators";
import { iconHTML } from "discourse-common/lib/icon-library";
import { escape } from "pretty-text/sanitizer";
import ENV from "discourse-common/config/environment";
const MAX_COMPONENTS = 4;
@ -43,7 +44,7 @@ export default Component.extend({
animate(isInitial) {
const $container = $(this.element);
const $list = $(this.element.querySelector(".components-list"));
if ($list.length === 0 || Ember.testing) {
if ($list.length === 0 || ENV.environment === 'test') {
return;
}
const duration = 300;

View File

@ -2,6 +2,7 @@ import { gt, equal } from "@ember/object/computed";
import Component from "@ember/component";
import { THEMES, COMPONENTS } from "admin/models/theme";
import { default as computed } from "ember-addons/ember-computed-decorators";
import { getOwner } from "@ember/application";
export default Component.extend({
THEMES: THEMES,
@ -70,7 +71,7 @@ export default Component.extend({
}
},
navigateToTheme(theme) {
Ember.getOwner(this)
getOwner(this)
.lookup("router:main")
.transitionTo("adminCustomizeThemes.show", theme);
}

View File

@ -51,7 +51,8 @@ export default Route.extend({
})
.catch(function(error) {
badge.set("preview_loading", false);
Ember.Logger.error(error);
// eslint-disable-next-line no-console
console.error(error);
bootbox.alert("Network error");
});
}

View File

@ -0,0 +1 @@
export default { environment: Ember.testing ? "test" : "development" };

View File

@ -96,6 +96,9 @@ var define, requirejs;
},
"@ember/component/helper": {
default: Ember.Helper
},
"@ember/error": {
default: Ember.error
}
};
}

View File

@ -48,6 +48,7 @@ import {
INLINE_ONEBOX_LOADING_CSS_CLASS,
INLINE_ONEBOX_CSS_CLASS
} from "pretty-text/context/inline-onebox-css-classes";
import ENV from "discourse-common/config/environment";
const REBUILD_SCROLL_MAP_EVENTS = ["composer:resized", "composer:typed-reply"];
@ -911,7 +912,7 @@ export default Component.extend({
// need to wait a bit for the "slide down" transition of the composer
later(
() => this.appEvents.trigger("composer:closed"),
Ember.testing ? 0 : 400
ENV.environment === "test" ? 0 : 400
);
});

View File

@ -12,6 +12,7 @@ import { load } from "pretty-text/oneboxer";
import { lookupCache } from "pretty-text/oneboxer-cache";
import { ajax } from "discourse/lib/ajax";
import afterTransition from "discourse/lib/after-transition";
import ENV from "discourse-common/config/environment";
export default Component.extend({
classNames: ["title-input"],
@ -83,7 +84,7 @@ export default Component.extend({
return;
}
if (Ember.testing) {
if (ENV.environment === "test") {
next(() =>
// not ideal but we don't want to run this in current
// runloop to avoid an error in console

View File

@ -1,4 +1,4 @@
import { notEmpty, empty } from "@ember/object/computed";
import { notEmpty, empty, equal } from "@ember/object/computed";
import Component from "@ember/component";
import { default as computed } from "ember-addons/ember-computed-decorators";
import DiscourseURL from "discourse/lib/url";
@ -24,7 +24,7 @@ export default Component.extend({
btnIcon: notEmpty("icon"),
btnLink: Ember.computed.equal("display", "link"),
btnLink: equal("display", "link"),
@computed("icon", "translatedLabel")
btnType(icon, translatedLabel) {

View File

@ -30,6 +30,7 @@ import { emojiSearch, isSkinTonableEmoji } from "pretty-text/emoji";
import { emojiUrlFor } from "discourse/lib/text";
import showModal from "discourse/lib/show-modal";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
// Our head can be a static string or a function that returns a string
// based on input (like for numbered lists).
@ -375,7 +376,7 @@ export default Component.extend({
}
// Debouncing in test mode is complicated
if (Ember.testing) {
if (ENV.environment === "test") {
this._updatePreview();
} else {
debounce(this, this._updatePreview, 30);

View File

@ -1,4 +1,5 @@
import Component from "@ember/component";
export default Component.extend({
classNames: ["d-date-time-input"],
date: null,

View File

@ -10,6 +10,8 @@ import {
emojiSearch
} from "pretty-text/emoji";
import { safariHacksDisabled } from "discourse/lib/utilities";
import ENV from "discourse-common/config/environment";
const { run } = Ember;
const PER_ROW = 11;
@ -509,7 +511,7 @@ export default Component.extend({
this.$picker.css(_.merge(attributes, options));
};
if (Ember.testing || !this.automaticPositioning) {
if (ENV.environment === "test" || !this.automaticPositioning) {
desktopPositioning();
return;
}

View File

@ -6,6 +6,7 @@ import { bufferedRender } from "discourse-common/lib/buffered-render";
import Category from "discourse/models/category";
import computed from "ember-addons/ember-computed-decorators";
import { REMINDER_TYPE } from "discourse/controllers/edit-topic-timer";
import ENV from "discourse-common/config/environment";
export default Component.extend(
bufferedRender({
@ -86,7 +87,7 @@ export default Component.extend(
buffer.push("</h3>");
// TODO Sam: concerned this can cause a heavy rerender loop
if (!Ember.testing) {
if (ENV.environment !== "test") {
this._delayedRerender = later(this, this.rerender, rerenderDelay);
}
}

View File

@ -14,6 +14,7 @@ import CardContentsBase from "discourse/mixins/card-contents-base";
import CleansUp from "discourse/mixins/cleans-up";
import { prioritizeNameInUx } from "discourse/lib/settings";
import { set } from "@ember/object";
import { getOwner } from "@ember/application";
export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
elementId: "user-card",
@ -174,7 +175,7 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
composePM(user, post) {
this._close();
Ember.getOwner(this)
getOwner(this)
.lookup("router:main")
.send("composePrivateMessage", user, post);
},

View File

@ -25,6 +25,7 @@ import { emojiUnescape } from "discourse/lib/text";
import { shortDate } from "discourse/lib/formatter";
import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
function loadDraft(store, opts) {
opts = opts || {};
@ -67,7 +68,7 @@ function loadDraft(store, opts) {
const _popupMenuOptionsCallbacks = [];
let _checkDraftPopup = !Ember.testing;
let _checkDraftPopup = !ENV.environment === "test";
export function toggleCheckDraftPopup(enabled) {
_checkDraftPopup = enabled;

View File

@ -1360,7 +1360,8 @@ export default Controller.extend(bufferedProperty("model"), {
if (callback) {
callback(this, data);
} else {
Ember.Logger.warn("unknown topic bus message type", data);
// eslint-disable-next-line no-console
console.warn("unknown topic bus message type", data);
}
}
}

View File

@ -1,5 +1,6 @@
import DiscourseURL from "discourse/lib/url";
import { currentThemeIds, refreshCSS } from "discourse/lib/theme-selector";
import ENV from "discourse-common/config/environment";
// Use the message bus for live reloading of components for faster development.
export default {
@ -43,7 +44,7 @@ export default {
});
// Useful to export this for debugging purposes
if (Discourse.Environment === "development" && !Ember.testing) {
if (Discourse.Environment === "development" && ENV.environment !== "test") {
window.DiscourseURL = DiscourseURL;
}

View File

@ -12,6 +12,7 @@ import {
isPushNotificationsEnabled
} from "discourse/lib/push-notifications";
import { set } from "@ember/object";
import ENV from "discourse-common/config/environment";
export default {
name: "subscribe-user-notifications",
@ -127,7 +128,7 @@ export default {
Discourse.set("assetVersion", data)
);
if (!Ember.testing) {
if (ENV.environment !== "test") {
bus.subscribe(alertChannel(user), data => onNotification(data, user));
initDesktopNotifications(bus, appEvents);

View File

@ -4,6 +4,7 @@ import DiscourseURL from "discourse/lib/url";
import { wantsNewWindow } from "discourse/lib/intercept-click";
import { selectedText } from "discourse/lib/utilities";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
export function isValidLink($link) {
// Do not track:
@ -99,7 +100,7 @@ export default {
let trackPromise = Promise.resolve();
if (tracking) {
if (!Ember.testing && navigator.sendBeacon) {
if (ENV.environment !== "test" && navigator.sendBeacon) {
const data = new FormData();
data.append("url", href);
data.append("post_id", postId);

View File

@ -28,14 +28,16 @@ function init(messageBus, appEvents) {
try {
keyValueStore.getItem(focusTrackerKey);
} catch (e) {
Ember.Logger.info(
// eslint-disable-next-line no-console
console.info(
"Discourse desktop notifications are disabled - localStorage denied."
);
return;
}
if (!("Notification" in window)) {
Ember.Logger.info(
// eslint-disable-next-line no-console
console.info(
"Discourse desktop notifications are disabled - not supported by browser"
);
return;
@ -49,7 +51,8 @@ function init(messageBus, appEvents) {
return;
}
} catch (e) {
Ember.Logger.warn(
// eslint-disable-next-line no-console
console.warn(
"Unexpected error, Notification is defined on window but not a responding correctly " +
e
);
@ -60,7 +63,8 @@ function init(messageBus, appEvents) {
// Preliminary checks passed, continue with setup
setupNotifications(appEvents);
} catch (e) {
Ember.Logger.error(e);
// eslint-disable-next-line no-console
console.error(e);
}
}

View File

@ -1,10 +1,12 @@
import ENV from "discourse-common/config/environment";
// Track visible elemnts on the screen.
const Eyeline = function Eyeline(selector) {
this.selector = selector;
};
Eyeline.prototype.update = function() {
if (Ember.testing) {
if (ENV.environment === "test") {
return;
}
@ -61,7 +63,7 @@ Eyeline.prototype.update = function() {
// Call this when we know aren't loading any more elements. Mark the rest as seen
Eyeline.prototype.flushRest = function() {
if (Ember.testing) {
if (ENV.environment === "test") {
return;
}

View File

@ -1,4 +1,5 @@
import deprecated from "discourse-common/lib/deprecated";
import ENV from "discourse-common/config/environment";
let mobileForced = false;
@ -12,7 +13,7 @@ const Mobile = {
this.isMobileDevice = mobileForced || $html.hasClass("mobile-device");
this.mobileView = mobileForced || $html.hasClass("mobile-view");
if (Ember.testing || mobileForced) {
if (ENV.environment === "test" || mobileForced) {
return;
}

View File

@ -1,8 +1,10 @@
import error from "@ember/error";
let _topicFooterButtons = {};
export function registerTopicFooterButton(button) {
if (!button.id) {
Ember.error(`Attempted to register a topic button: ${button} with no id.`);
error(`Attempted to register a topic button: ${button} with no id.`);
return;
}
@ -52,7 +54,7 @@ export function registerTopicFooterButton(button) {
!normalizedButton.title &&
!normalizedButton.translatedTitle
) {
Ember.error(
error(
`Attempted to register a topic button: ${button.id} with no icon or title.`
);
return;

View File

@ -1,11 +1,12 @@
import { defaultHomepage } from "discourse/lib/utilities";
import { rewritePath } from "discourse/lib/url";
import ENV from "discourse-common/config/environment";
const rootURL = Discourse.BaseUri;
const BareRouter = Ember.Router.extend({
rootURL,
location: Ember.testing ? "none" : "discourse-location",
location: ENV.environment === "test" ? "none" : "discourse-location",
handleURL(url) {
url = rewritePath(url);

View File

@ -2,10 +2,11 @@ import { scheduleOnce } from "@ember/runloop";
import DiscourseURL from "discourse/lib/url";
import { deprecated } from "discourse/mixins/scroll-top";
import Mixin from "@ember/object/mixin";
import ENV from "discourse-common/config/environment";
const context = {
_scrollTop() {
if (Ember.testing) {
if (ENV.environment === "test") {
return;
}
$(document).scrollTop(0);

View File

@ -3,6 +3,7 @@ import { scheduleOnce } from "@ember/runloop";
import DiscourseRoute from "discourse/routes/discourse";
import DiscourseURL from "discourse/lib/url";
import Draft from "discourse/models/draft";
import ENV from "discourse-common/config/environment";
// This route is used for retrieving a topic based on params
export default DiscourseRoute.extend({
@ -80,7 +81,7 @@ export default DiscourseRoute.extend({
}
})
.catch(e => {
if (!Ember.testing) {
if (ENV.environment !== "test") {
// eslint-disable-next-line no-console
console.log("Could not view topic", e);
}

View File

@ -22,8 +22,8 @@ export default class Connector {
);
}
const container = Ember.getOwner
? Ember.getOwner(mounted)
const container = getOwner
? getOwner(mounted)
: mounted.container;
let view;

View File

@ -3,6 +3,7 @@ import { scheduleOnce } from "@ember/runloop";
import { diff, patch } from "virtual-dom";
import { queryRegistry } from "discourse/widgets/widget";
import DirtyKeys from "discourse/lib/dirty-keys";
import ENV from "discourse-common/config/environment";
export default class WidgetGlue {
constructor(name, register, attrs) {
@ -34,7 +35,7 @@ export default class WidgetGlue {
cancel(this._timeout);
// in test mode return early if store cannot be found
if (Ember.testing) {
if (ENV.environment === "test") {
try {
this.register.lookup("service:store");
} catch (e) {

View File

@ -5,11 +5,12 @@ import { avatarAtts } from "discourse/widgets/actions-summary";
import { h } from "virtual-dom";
import showModal from "discourse/lib/show-modal";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
const LIKE_ACTION = 2;
function animateHeart($elem, start, end, complete) {
if (Ember.testing) {
if (ENV.environment === "test") {
return run(this, complete);
}

View File

@ -11,6 +11,7 @@ import {
import { h } from "virtual-dom";
import DecoratorHelper from "discourse/widgets/decorator-helper";
import { Promise } from "rsvp";
import ENV from "discourse-common/config/environment";
const _registry = {};
@ -118,7 +119,7 @@ export default class Widget {
this.keyValueStore = register.lookup("key-value-store:main");
// Helps debug widgets
if (Discourse.Environment === "development" || Ember.testing) {
if (Discourse.Environment === "development" || ENV.environment === "test") {
const ds = this.defaultState(attrs);
if (typeof ds !== "object") {
throw new Error(`defaultState must return an object`);

View File

@ -319,7 +319,8 @@ I18n.enableVerboseLocalization = function() {
if (!_.isEmpty(value)) {
message += ", parameters: " + JSON.stringify(value);
}
Ember.Logger.info(message);
// eslint-disable-next-line no-console
console.info(message);
}
return t.apply(I18n, [scope, value]) + " (#" + current + ")";
};

View File

@ -1,8 +1,9 @@
import getUrl from "discourse-common/lib/get-url";
import ENV from "discourse-common/config/environment";
const Router = Ember.Router.extend({
rootURL: getUrl("/wizard/"),
location: Ember.testing ? "none" : "history"
location: ENV.environment === "test" ? "none" : "history"
});
Router.map(function() {