Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: wait for initial load in benchmarks #390

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 4 additions & 15 deletions test/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import { waitForPickerInitialLoad } from './utils.js'

function instrumentPickerLoading () {
const observer = new PerformanceObserver(entries => {
for (const { name, startTime, duration } of entries.getEntries()) {
if (name === 'initialLoad') {
// test to make sure the picker loaded with no errors
const hasErrors = document.querySelector('emoji-picker') && document.querySelector('emoji-picker')
.shadowRoot.querySelector('.message:not(.gone)')
if (hasErrors) {
console.error('picker is showing an error message')
} else {
performance.measure('benchmark-total', { start: startTime, duration })
}
}
}
waitForPickerInitialLoad().then(entry => {
performance.measure('benchmark-total', { start: entry.startTime, duration: entry.duration })
})

observer.observe({ entryTypes: ['measure'] })
}

function useFakeEtag () {
Expand Down
4 changes: 2 additions & 2 deletions test/benchmark/change-tab.benchmark.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Picker from './picker.js'
import { waitForElementWithId, postRaf } from './utils.js'
import { waitForElementWithId, postRaf, waitForPickerInitialLoad } from './utils.js'

const picker = new Picker()
document.body.appendChild(picker)

await waitForElementWithId(picker.shadowRoot, 'emo-😀')
await waitForPickerInitialLoad()
await postRaf()
const peopleTabButton = picker.shadowRoot.querySelector('[role="tab"][aria-label="People and body"]')

Expand Down
4 changes: 2 additions & 2 deletions test/benchmark/search.benchmark.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Picker from './picker.js'
import { waitForElementWithId, postRaf } from './utils.js'
import { waitForElementWithId, postRaf, waitForPickerInitialLoad } from './utils.js'

const picker = new Picker()
document.body.appendChild(picker)

await waitForElementWithId(picker.shadowRoot, 'emo-😀')
await waitForPickerInitialLoad()
await postRaf()
const searchBox = picker.shadowRoot.querySelector('[role="combobox"]')

Expand Down
23 changes: 23 additions & 0 deletions test/benchmark/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,26 @@ export const waitForElementWithId = async (root, id) => {
await raf()
}
}

export const waitForPickerInitialLoad = () => {
return new Promise((resolve, reject) => {
const observer = new PerformanceObserver(entries => {
for (const entry of entries.getEntries()) {
if (entry.name === 'initialLoad') {
// test to make sure the picker loaded with no errors
const hasErrors = document.querySelector('emoji-picker') && document.querySelector('emoji-picker')
.shadowRoot.querySelector('.message:not(.gone)')
if (hasErrors) {
const err = new Error('picker is showing an error message')
console.error(err)
reject(err)
} else {
resolve(entry)
}
observer.disconnect()
}
}
})
observer.observe({ entryTypes: ['measure'] })
})
}