test: count store listeners in memory leak test (#1853)
This commit is contained in:
parent
2f41494a9a
commit
1466371909
|
@ -11,8 +11,8 @@ const listStore = new ListStore()
|
|||
|
||||
listStore.computeForRealm('intersectionStates', {})
|
||||
|
||||
if (process.browser && process.env.NODE_ENV !== 'production') {
|
||||
window.listStore = listStore
|
||||
if (process.browser) {
|
||||
window.__listStore = listStore // for debugging
|
||||
}
|
||||
|
||||
export { listStore }
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
homeNavButton, modalDialog, notificationsNavButton,
|
||||
scrollToStatus,
|
||||
scrollToTop,
|
||||
settingsNavButton, sleep
|
||||
settingsNavButton, sleep, getNumStoreListeners
|
||||
} from '../utils'
|
||||
import { loginAsFoobar } from '../roles'
|
||||
import { installDomListenerListener, getNumDomListeners } from '../spyDomListeners'
|
||||
|
@ -27,14 +27,17 @@ async function runMemoryLeakTest (t, firstStep, secondStep) {
|
|||
await sleep(1000)
|
||||
const numSyntheticListeners = await getNumSyntheticListeners()
|
||||
const numDomListeners = await getNumDomListeners()
|
||||
const numStoreListeners = await getNumStoreListeners()
|
||||
await t
|
||||
.expect(numSyntheticListeners).typeOf('number')
|
||||
.expect(numDomListeners).typeOf('number')
|
||||
.expect(numStoreListeners).typeOf('number')
|
||||
await secondStep()
|
||||
await sleep(1000)
|
||||
await t
|
||||
.expect(getNumSyntheticListeners()).eql(numSyntheticListeners)
|
||||
.expect(getNumDomListeners()).eql(numDomListeners)
|
||||
.expect(getNumStoreListeners()).eql(numStoreListeners)
|
||||
}
|
||||
|
||||
async function goToSettings (t) {
|
||||
|
|
|
@ -135,6 +135,19 @@ export const getNumSyntheticListeners = exec(() => {
|
|||
.reduce((a, b) => a + b, 0)
|
||||
})
|
||||
|
||||
export const getNumStoreListeners = exec(() => {
|
||||
function getStoreHandlers (storeName) {
|
||||
return window[storeName] ? window[storeName]._handlers : {}
|
||||
}
|
||||
|
||||
const values = 'values' // prevent Babel from transpiling Object.values
|
||||
return Object[values](getStoreHandlers('__store'))
|
||||
.concat(Object[values](getStoreHandlers('__listStore')))
|
||||
.concat(Object[values](getStoreHandlers('__virtualListStore')))
|
||||
.map(arr => arr.length)
|
||||
.reduce((a, b) => a + b, 0)
|
||||
})
|
||||
|
||||
export const getMediaScrollLeft = exec(() => document.querySelector('.media-scroll').scrollLeft || 0)
|
||||
|
||||
export const getActiveElementClassList = exec(() =>
|
||||
|
|
Loading…
Reference in a new issue