test: count store listeners in memory leak test (#1853)

This commit is contained in:
Nolan Lawson 2020-08-29 19:18:53 -07:00 committed by GitHub
parent 2f41494a9a
commit 1466371909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -11,8 +11,8 @@ const listStore = new ListStore()
listStore.computeForRealm('intersectionStates', {}) listStore.computeForRealm('intersectionStates', {})
if (process.browser && process.env.NODE_ENV !== 'production') { if (process.browser) {
window.listStore = listStore window.__listStore = listStore // for debugging
} }
export { listStore } export { listStore }

View File

@ -10,7 +10,7 @@ import {
homeNavButton, modalDialog, notificationsNavButton, homeNavButton, modalDialog, notificationsNavButton,
scrollToStatus, scrollToStatus,
scrollToTop, scrollToTop,
settingsNavButton, sleep settingsNavButton, sleep, getNumStoreListeners
} from '../utils' } from '../utils'
import { loginAsFoobar } from '../roles' import { loginAsFoobar } from '../roles'
import { installDomListenerListener, getNumDomListeners } from '../spyDomListeners' import { installDomListenerListener, getNumDomListeners } from '../spyDomListeners'
@ -27,14 +27,17 @@ async function runMemoryLeakTest (t, firstStep, secondStep) {
await sleep(1000) await sleep(1000)
const numSyntheticListeners = await getNumSyntheticListeners() const numSyntheticListeners = await getNumSyntheticListeners()
const numDomListeners = await getNumDomListeners() const numDomListeners = await getNumDomListeners()
const numStoreListeners = await getNumStoreListeners()
await t await t
.expect(numSyntheticListeners).typeOf('number') .expect(numSyntheticListeners).typeOf('number')
.expect(numDomListeners).typeOf('number') .expect(numDomListeners).typeOf('number')
.expect(numStoreListeners).typeOf('number')
await secondStep() await secondStep()
await sleep(1000) await sleep(1000)
await t await t
.expect(getNumSyntheticListeners()).eql(numSyntheticListeners) .expect(getNumSyntheticListeners()).eql(numSyntheticListeners)
.expect(getNumDomListeners()).eql(numDomListeners) .expect(getNumDomListeners()).eql(numDomListeners)
.expect(getNumStoreListeners()).eql(numStoreListeners)
} }
async function goToSettings (t) { async function goToSettings (t) {

View File

@ -135,6 +135,19 @@ export const getNumSyntheticListeners = exec(() => {
.reduce((a, b) => a + b, 0) .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 getMediaScrollLeft = exec(() => document.querySelector('.media-scroll').scrollLeft || 0)
export const getActiveElementClassList = exec(() => export const getActiveElementClassList = exec(() =>