REFACTOR: Use imports for `sinon` and `setResolver`

I also took the opportunity with this commit to move some test specific
stuff out of `discourse-loader` which is loaded on the front end of the
application. The test module building now happens in the `test_helper`
bundle.
This commit is contained in:
Robin Ward 2020-10-09 12:00:46 -04:00
parent 4326827a4e
commit 3862036422
9 changed files with 40 additions and 21 deletions

View File

@ -7,6 +7,7 @@
"moduleFor": "off",
"moduleForComponent": "off",
"testStart": "off",
"testDone": "off"
"testDone": "off",
"sinon": "off"
}
}

View File

@ -146,26 +146,13 @@ var define, requirejs;
"@ember/object/internals": {
guidFor: Ember.guidFor,
},
"@ember/test-helpers": {
setResolver: window.setResolver,
},
I18n: {
// eslint-disable-next-line
default: I18n,
},
pretender: {
default: window.Pretender,
},
"ember-qunit": {
moduleFor: window.moduleFor,
moduleForComponent: window.moduleForComponent,
},
qunit:
typeof window.QUnit !== "undefined"
? {
default: window.QUnit,
test: window.QUnit.test,
skip: window.QUnit.skip,
module: window.QUnit.module,
}
: undefined,
};
}

View File

@ -24,9 +24,11 @@ import { clearAppEventsCache } from "discourse/services/app-events";
import QUnit from "qunit";
import MessageBus from "message-bus-client";
import deprecated from "discourse-common/lib/deprecated";
import sinon from "sinon";
import { setResolver } from "@ember/test-helpers";
export default function setupTests(App) {
window.setResolver(buildResolver("discourse").create({ namespace: App }));
setResolver(buildResolver("discourse").create({ namespace: App }));
sinon.config = {
injectIntoThis: false,

View File

@ -1,6 +1,5 @@
// discourse-skip-module
/*global document, sinon, QUnit, Logster */
//= require env
//= require jquery.debug
//= require jquery.ui.widget
@ -41,8 +40,7 @@
//= require_tree ../../admin/tests/admin
//= require plugin_tests
//= require setup-tests
//= require_self
//
//= require test-shims
//= require jquery.magnific-popup.min.js
let setupTests = require("discourse/tests/setup-tests").default;

View File

@ -8,6 +8,7 @@ import {
durationTiny,
} from "discourse/lib/formatter";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import sinon from "sinon";
discourseModule("lib:formatter", {
beforeEach() {

View File

@ -4,6 +4,7 @@ import createStore from "discourse/tests/helpers/create-store";
import Category from "discourse/models/category";
import { NotificationLevels } from "discourse/lib/notification-levels";
import User from "discourse/models/user";
import sinon from "sinon";
module("model:topic-tracking-state", {
beforeEach() {

View File

@ -0,0 +1,27 @@
// discourse-skip-module
define("sinon", () => {
return { default: window.sinon };
});
define("qunit", () => {
return {
default: window.QUnit,
test: window.QUnit.test,
skip: window.QUnit.skip,
module: window.QUnit.module,
};
});
define("ember-qunit", () => {
return {
moduleFor: window.moduleFor,
moduleForComponent: window.moduleForComponent,
};
});
define("@ember/test-helpers", () => {
return {
setResolver: window.setResolver,
};
});
define("pretender", () => {
return { default: window.Pretender };
});

View File

@ -23,6 +23,7 @@
//= require_tree ./models
//= require_tree ./components
//= require ./wizard-pretender
//= require test-shims
// Trick JSHint into allow document.write
var d = document;

View File

@ -1,5 +1,6 @@
import I18n from "I18n";
import LocalDateBuilder from "./local-date-builder";
import sinon from "sinon";
const UTC = "Etc/UTC";
const SYDNEY = "Australia/Sydney";