janl commented on code in PR #9212:
URL: https://github.com/apache/pouchdb/pull/9212#discussion_r3001922737
##########
tests/multitab/user_agent.js:
##########
@@ -0,0 +1,53 @@
+'use strict'
+
+const playwright = require('playwright')
+
+const ADAPTERS = process.env.ADAPTERS || 'indexeddb'
+const CLIENT = process.env.CLIENT || 'firefox'
+const SHELL_URL = 'http://127.0.0.1:8000/tests/multitab/shell.html'
+
+class UserAgent {
+ static async start () {
+ let browser = await playwright[CLIENT].launch()
+ let context = await browser.newContext()
+ return new UserAgent(ADAPTERS, browser, context)
+ }
+
+ constructor (adapter, browser, context) {
+ this._adapter = adapter
+ this._browser = browser
+ this._context = context
+ this._pages = new Map()
+ }
+
+ async stop () {
+ await this._browser.close()
+ }
+
+ async eval (pageId, fn) {
+ let page = await this._getPage(pageId)
+ return page.evaluate(fn)
+ }
+
+ _getPage (id) {
+ if (!this._pages.has(id)) {
+ this._pages.set(id, this._setupPage())
+ }
+ return this._pages.get(id)
+ }
+
+ async _setupPage () {
+ let page = await this._context.newPage()
+ await page.goto(SHELL_URL)
+
+ if (this._adapter === 'idb') {
+ await page.evaluate(() => window.__pouch__ = new PouchDB('testdb', {
adapter: 'idb' }))
+ } else if (this._adapter === 'indexeddb') {
+ await page.evaluate(() => window.__pouch__ = new PouchDB('testdb', {
adapter: 'indexeddb' }))
+ }
Review Comment:
super nitpick, but would we want to separate validating that `this._adapter`
`idb` or `indexeddb` from instantiating a new pouch and for that just pass
in`{adapter: this._adapter}`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]