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

Reuse dom-testing-library in same execution context #69

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
70 changes: 70 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const path = require('path')
const Benchmark = require('benchmark')
const puppeteer = require('puppeteer')
const {queries: baseQueries, getDocument} = require('pptr-testing-library')
const {queries: latestQueries} = require('../')

const suite = new Benchmark.Suite('pptr-testing-library')

async function main() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(
`file://${path.join(__dirname, '..', 'test/fixtures/page.html')}`
)
const document = await getDocument(page)

// add tests
suite
.add({
name: 'base',
defer: true,
fn(deferred) {
baseQueries.getByAltText(document, 'Image A').then(result => {
if (result) {
deferred.resolve()
} else {
throw new Error('Image not found.')
}
})
},
})
.add({
name: 'latest',
defer: true,
fn(deferred) {
latestQueries.getByAltText(document, 'Image A').then(result => {
if (result) {
deferred.resolve()
} else {
throw new Error('Image not found.')
}
})
},
})
.add({
name: 'querySelector',
defer: true,
fn(deferred) {
page.$('img[alt="Image A"]').then(result => {
if (result) {
deferred.resolve()
} else {
throw new Error('Image not found.')
}
})
},
})
// add listeners
.on('cycle', event => {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
browser.close()
})
// run async
.run({async: true})
}

main()
Loading