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

issue-1763
Nolan Lawson 2020-08-29 19:18:53 -07:00 zatwierdzone przez GitHub
rodzic 2f41494a9a
commit 1466371909
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 19 dodań i 3 usunięć

Wyświetl plik

@ -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 }

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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(() =>