From aa4b50777b07ba38eba6ad6564414d7d9d9cf56b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 4 May 2018 13:09:29 -0400 Subject: [PATCH] Polyfill memory leak prevention. --- addon-test-support/ember-qunit/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addon-test-support/ember-qunit/index.js b/addon-test-support/ember-qunit/index.js index a3e7cbd2..25b6c691 100644 --- a/addon-test-support/ember-qunit/index.js +++ b/addon-test-support/ember-qunit/index.js @@ -243,6 +243,21 @@ export function setupTestIsolationValidation() { QUnit.done(reportIfTestNotIsolated); } +// This polyfills the changes from https://github.com/qunitjs/qunit/pull/1279 +// and should be removed when that change is released and included in a release +// version of QUnit +function polyfillMemoryLeakPrevention() { + QUnit.testDone(function() { + // release the test callback + QUnit.config.current.callback = undefined; + }); + + QUnit.moduleDone(function() { + // release the module hooks + QUnit.config.current.module.hooks = {}; + }); +} + /** @method start @param {Object} [options] Options to be used for enabling/disabling behaviors @@ -260,6 +275,7 @@ export function setupTestIsolationValidation() { of `Ember.onerror` will be disabled. @param {Boolean} [options.setupTestIsolationValidation] If `false` test isolation validation will be disabled. + @param {Boolean} [options._polyfillMemoryLeakPrevention] If `false` the polyfilled memory leak prevention will not be enabled. */ export function start(options = {}) { if (options.loadTests !== false) { @@ -289,6 +305,10 @@ export function start(options = {}) { setupTestIsolationValidation(); } + if (options._polyfillMemoryLeakPrevention !== false) { + polyfillMemoryLeakPrevention(); + } + if (options.startTests !== false) { startTests(); }