Last active
November 3, 2016 18:45
-
-
Save kiwiupover/1d521118eefd92c4ad84376f98f6c7ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { module } from 'qunit'; | |
import Ember from 'ember'; | |
import startApp from '../helpers/start-app'; | |
import destroyApp from '../helpers/destroy-app'; | |
const { RSVP: { Promise } } = Ember; | |
const map = new WeakMap(); | |
const registryKey = {}; | |
const contKey = {}; | |
const ownerKey = {}; | |
export default function(name, options = {}) { | |
module(name, { | |
beforeEach() { | |
this.application = startApp(); | |
map.set(registryKey, this.application.registry); | |
map.set(contKey, this.application.__container__); | |
map.set(ownerKey, this.application.__container__.owner); | |
if (options.beforeEach) { | |
return options.beforeEach.apply(this, arguments); | |
} | |
}, | |
afterEach() { | |
let afterEach = options.afterEach && options.afterEach.apply(this, arguments); | |
return Promise.resolve(afterEach).then(() => { | |
destroyApp(this.application); | |
if (typeof window.gc === 'function') { | |
window.gc(); | |
if (map.get(registryKey)) { | |
console.log('we have a leak registryKey', map.get(registryKey)); | |
} | |
if (map.get(contKey)) { | |
console.log('we have a leak containerKey', map.get(contKey)); | |
} | |
if (map.get(ownerKey)) { | |
console.log('we have a leak ownerKey', map.get(ownerKey)); | |
} | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment