test: add basic memory leak test (#1650)

* test: add basic memory leak test

* try to fix test
pull/1654/head
Nolan Lawson 2019-11-23 19:11:15 -08:00 zatwierdzone przez GitHub
rodzic 14762c4a5f
commit 95ef639b21
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 59 dodań i 6 usunięć

Wyświetl plik

@ -2,8 +2,8 @@
const callbacks = {}
if (process.browser && process.env.NODE_ENV !== 'production') {
window.delegateCallbacks = callbacks
if (process.browser) {
window.__delegateCallbacks = callbacks
}
function onEvent (e) {

Wyświetl plik

@ -2,8 +2,8 @@ import EventEmitter from 'events-light'
export const eventBus = new EventEmitter()
if (process.browser && process.env.NODE_ENV !== 'production') {
window.eventBus = eventBus
if (process.browser) {
window.__eventBus = eventBus
}
export function on (eventName, component, method) {

Wyświetl plik

@ -4,8 +4,8 @@ const DEBOUNCE_DELAY = 700
const listeners = new Set()
if (process.browser && process.env.NODE_ENV !== 'production') {
window.resizeListeners = listeners
if (process.browser) {
window.__resizeListeners = listeners
}
if (process.browser) {

Wyświetl plik

@ -0,0 +1,46 @@
import {
composeInput,
getNthAutosuggestionResult,
getNumSyntheticListeners,
getUrl,
homeNavButton,
scrollToStatus,
scrollToTop,
settingsNavButton, sleep
} from '../utils'
import { loginAsFoobar } from '../roles'
fixture`038-memory-leaks.js`
.page`http://localhost:4002`
async function goToStartPoint (t) {
await t
.click(settingsNavButton)
.expect(getUrl()).contains('/settings')
}
async function interactAndGoToEndPoint (t) {
await t
.click(homeNavButton)
.expect(getUrl()).eql('http://localhost:4002/')
await scrollToStatus(t, 15)
await scrollToTop()
await t
.typeText(composeInput, 'hey @qu')
.expect(getNthAutosuggestionResult(1).find('.sr-only').innerText).contains('@quux')
.click(settingsNavButton)
.expect(getUrl()).contains('/settings')
}
test('Does not leak synthetic listeners', async t => {
await loginAsFoobar(t)
await goToStartPoint(t)
await sleep(1000)
const numSyntheticListeners = await getNumSyntheticListeners()
await t
.expect(numSyntheticListeners).typeOf('number')
await interactAndGoToEndPoint(t)
await sleep(1000)
await t
.expect(getNumSyntheticListeners()).eql(numSyntheticListeners)
})

Wyświetl plik

@ -119,6 +119,13 @@ export const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeo
export const getUrl = exec(() => window.location.href)
export const getNumSyntheticListeners = exec(() => {
return Object.keys(window.__eventBus.$e).map(key => window.__eventBus.listenerCount(key))
.concat(window.__resizeListeners.size)
.concat(Object.keys(window.__delegateCallbacks).length)
.reduce((a, b) => a + b, 0)
})
export const getMediaScrollLeft = exec(() => document.querySelector('.media-scroll').scrollLeft || 0)
export const getActiveElementClassList = exec(() =>