REFACTOR: Test Memory Usage Fixes (#7769)

approved
#1

REFACTOR: Test Memory Usage Fixes (#7769)

  • Calling Discourse.reset() creates a new container We should run our de-initializers only after acceptance tests, since initializers are not run outside of acceptance tests anyway, and the container at this point can be passed properly to the teardown() method.

  • Remove Discourse.reset from tests This would cause a new container to be created which leaks many objects.

  • updateCurrentUser is more accurate than replaceCurrentUser

diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
index 586f6b9..6a126d6 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-disabled-test.js.es6
@@ -1,4 +1,4 @@
-import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
+import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
 import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
 import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
 
@@ -14,7 +14,7 @@ acceptance("Poll Builder - polls are disabled", {
 });
 
 test("regular user - sufficient trust level", assert => {
-  replaceCurrentUser({ staff: false, trust_level: 3 });
+  updateCurrentUser({ staff: false, trust_level: 3 });
 
   displayPollBuilderButton();
 
@@ -27,7 +27,7 @@ test("regular user - sufficient trust level", assert => {
 });
 
 test("regular user - insufficient trust level", assert => {
-  replaceCurrentUser({ staff: false, trust_level: 1 });
+  updateCurrentUser({ staff: false, trust_level: 1 });
 
   displayPollBuilderButton();
 
@@ -40,7 +40,7 @@ test("regular user - insufficient trust level", assert => {
 });
 
 test("staff", assert => {
-  replaceCurrentUser({ staff: true });
+  updateCurrentUser({ staff: true });
 
   displayPollBuilderButton();
 
diff --git a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6 b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
index 933e62a..8880c28 100644
--- a/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
+++ b/plugins/poll/test/javascripts/acceptance/poll-builder-enabled-test.js.es6
@@ -1,4 +1,4 @@
-import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
+import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
 import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
 import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
 
@@ -14,7 +14,7 @@ acceptance("Poll Builder - polls are enabled", {
 });
 
 test("regular user - sufficient trust level", assert => {
-  replaceCurrentUser({ staff: false, trust_level: 1 });
+  updateCurrentUser({ staff: false, trust_level: 1 });
 
   displayPollBuilderButton();
 
@@ -27,7 +27,7 @@ test("regular user - sufficient trust level", assert => {
 });
 
 test("regular user - insufficient trust level", assert => {
-  replaceCurrentUser({ staff: false, trust_level: 0 });
+  updateCurrentUser({ staff: false, trust_level: 0 });
 
   displayPollBuilderButton();
 
@@ -40,7 +40,7 @@ test("regular user - insufficient trust level", assert => {
 });
 
 test("staff - with insufficient trust level", assert => {
-  replaceCurrentUser({ staff: true, trust_level: 0 });
+  updateCurrentUser({ staff: true, trust_level: 0 });
 
   displayPollBuilderButton();
 
diff --git a/test/javascripts/acceptance/badges-test.js.es6 b/test/javascripts/acceptance/badges-test.js.es6
index a9cb69a..8ef0d30 100644
--- a/test/javascripts/acceptance/badges-test.js.es6
+++ b/test/javascripts/acceptance/badges-test.js.es6
@@ -1,7 +1,7 @@
 import selectKit from "helpers/select-kit-helper";
-import { acceptance, logIn } from "helpers/qunit-helpers";
+import { acceptance } from "helpers/qunit-helpers";
 
-acceptance("Badges");
+acceptance("Badges", { loggedIn: true });
 
 QUnit.test("Visit Badge Pages", async assert => {
   await visit("/badges");
@@ -17,10 +17,7 @@ QUnit.test("Visit Badge Pages", async assert => {
 });
 
 QUnit.test("shows correct badge titles to choose from", async assert => {
-  logIn();
-  Discourse.reset();
   const availableBadgeTitles = selectKit(".select-kit");
-
   await visit("/badges/50/custombadge");
   await availableBadgeTitles.expand();
   assert.ok(availableBadgeTitles.rowByIndex(1).name() === "CustomBadge");
diff --git a/test/javascripts/acceptance/composer-actions-test.js.es6 b/test/javascripts/acceptance/composer-actions-test.js.es6
index fd6eb58..7f690dc 100644
--- a/test/javascripts/acceptance/composer-actions-test.js.es6
+++ b/test/javascripts/acceptance/composer-actions-test.js.es6
@@ -1,5 +1,5 @@
 import selectKit from "helpers/select-kit-helper";
-import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
+import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
 import { _clearSnapshots } from "select-kit/components/composer-actions";
 import { toggleCheckDraftPopup } from "discourse/controllers/composer";
 
@@ -305,7 +305,7 @@ QUnit.test("replying to post - toggle_topic_bump", async assert => {
 QUnit.test("replying to post as staff", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  replaceCurrentUser({ staff: true, admin: false });
+  updateCurrentUser({ staff: true, admin: false });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
@@ -317,7 +317,7 @@ QUnit.test("replying to post as staff", async assert => {
 QUnit.test("replying to post as TL3 user", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  replaceCurrentUser({ staff: false, admin: false, trust_level: 3 });
+  updateCurrentUser({ staff: false, admin: false, trust_level: 3 });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
@@ -335,7 +335,7 @@ QUnit.test("replying to post as TL3 user", async assert => {
 QUnit.test("replying to post as TL4 user", async assert => {
   const composerActions = selectKit(".composer-actions");
 
-  replaceCurrentUser({ staff: false, admin: false, trust_level: 4 });
+  updateCurrentUser({ staff: false, admin: false, trust_level: 4 });
   await visit("/t/internationalization-localization/280");
   await click("article#post_3 button.reply");
   await composerActions.expand();
diff --git a/test/javascripts/acceptance/composer-topic-links-test.js.es6 b/test/javascripts/acceptance/composer-topic-links-test.js.es6
index f4e0550..8e72180 100644
--- a/test/javascripts/acceptance/composer-topic-links-test.js.es6
+++ b/test/javascripts/acceptance/composer-topic-links-test.js.es6
@@ -1,4 +1,4 @@
-import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
+import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
 
 acceptance("Composer topic featured links", {
   loggedIn: true,
@@ -156,7 +156,7 @@ acceptance("Composer topic featured links when uncategorized is not allowed", {
 });
 
 QUnit.test("Pasting a link enables the text input area", async assert => {
-  replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
+  updateCurrentUser({ admin: false, staff: false, trust_level: 1 });
 
   await visit("/");
   await click("#create-topic");
diff --git a/test/javascripts/acceptance/composer-uncategorized-test.js.es6 b/test/javascripts/acceptance/composer-uncategorized-test.js.es6
index c65c759..93fc5eb 100644
--- a/test/javascripts/acceptance/composer-uncategorized-test.js.es6
+++ b/test/javascripts/acceptance/composer-uncategorized-test.js.es6
@@ -1,5 +1,5 @@
 import selectKit from "helpers/select-kit-helper";
-import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
+import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
 
 acceptance("Composer and uncategorized is not allowed", {
   loggedIn: true,
@@ -18,7 +18,7 @@ acceptance("Composer and uncategorized is not allowed", {
 });
 
 QUnit.test("Disable body until category is selected", async assert => {
-  replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
+  updateCurrentUser({ admin: false, staff: false, trust_level: 1 });
 
   await visit("/");
   await click("#create-topic");

[... diff too long, it was truncated ...]

GitHub sha: a8793d0d

1 Like
Approved #2