Skip to content

Instantly share code, notes, and snippets.

@kiwiupover
Last active November 3, 2016 18:45
Show Gist options
  • Save kiwiupover/1d521118eefd92c4ad84376f98f6c7ba to your computer and use it in GitHub Desktop.
Save kiwiupover/1d521118eefd92c4ad84376f98f6c7ba to your computer and use it in GitHub Desktop.
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