make key optional
This commit is contained in:
parent
512da41375
commit
625273c2c0
|
|
@ -148,9 +148,9 @@ scheme.IndexedDBDatabase = tObject({
|
||||||
stores: tArray(tObject({
|
stores: tArray(tObject({
|
||||||
name: tString,
|
name: tString,
|
||||||
autoIncrement: tBoolean,
|
autoIncrement: tBoolean,
|
||||||
keyPath: tArray(tString),
|
keyPath: tOptional(tArray(tString)),
|
||||||
records: tArray(tObject({
|
records: tArray(tObject({
|
||||||
key: tString,
|
key: tOptional(tString),
|
||||||
value: tString,
|
value: tString,
|
||||||
})),
|
})),
|
||||||
indexes: tArray(tObject({
|
indexes: tArray(tObject({
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: key.toString(),
|
key: objectStore.keyPath === null ? key.toString() : undefined,
|
||||||
value: JSON.stringify(record)
|
value: JSON.stringify(record)
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
@ -569,7 +569,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
records: records.filter(Boolean),
|
records: records.filter(Boolean),
|
||||||
indexes,
|
indexes,
|
||||||
autoIncrement: objectStore.autoIncrement,
|
autoIncrement: objectStore.autoIncrement,
|
||||||
keyPath: Array.isArray(objectStore.keyPath) ? objectStore.keyPath : [objectStore.keyPath],
|
keyPath: objectStore.keyPath === null ? undefined : (Array.isArray(objectStore.keyPath) ? objectStore.keyPath : [objectStore.keyPath]),
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -685,7 +685,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
|
|
||||||
await Promise.all((originState.indexedDB || []).map(async dbInfo => {
|
await Promise.all((originState.indexedDB || []).map(async dbInfo => {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const openRequest = indexedDB.open(dbInfo.name, dbInfo.version);
|
const openRequest = indexedDB.open(dbInfo.name, dbInfo.version);
|
||||||
openRequest.addEventListener('upgradeneeded', () => {
|
openRequest.addEventListener('upgradeneeded', () => {
|
||||||
const db = openRequest.result;
|
const db = openRequest.result;
|
||||||
|
|
@ -698,7 +698,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
openRequest.addEventListener('success', async () => {
|
openRequest.addEventListener('success', async () => {
|
||||||
const db = openRequest.result;
|
const db = openRequest.result;
|
||||||
const transaction = db.transaction(db.objectStoreNames, 'readwrite');
|
const transaction = db.transaction(db.objectStoreNames, 'readwrite');
|
||||||
Promise.all(dbInfo.stores.flatMap(store => {
|
await Promise.all(dbInfo.stores.flatMap(store => {
|
||||||
const objectStore = transaction.objectStore(store.name);
|
const objectStore = transaction.objectStore(store.name);
|
||||||
return store.records.map(record => new Promise((resolve, reject) => {
|
return store.records.map(record => new Promise((resolve, reject) => {
|
||||||
const request = objectStore.add(
|
const request = objectStore.add(
|
||||||
|
|
@ -708,7 +708,10 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
request.addEventListener('success', resolve);
|
request.addEventListener('success', resolve);
|
||||||
request.addEventListener('error', reject);
|
request.addEventListener('error', reject);
|
||||||
}));
|
}));
|
||||||
})).then(resolve, reject);
|
}));
|
||||||
|
transaction.commit();
|
||||||
|
transaction.addEventListener('complete', () => resolve());
|
||||||
|
transaction.addEventListener('error', () => reject(transaction.error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
4
packages/protocol/src/channels.d.ts
vendored
4
packages/protocol/src/channels.d.ts
vendored
|
|
@ -277,9 +277,9 @@ export type IndexedDBDatabase = {
|
||||||
stores: {
|
stores: {
|
||||||
name: string,
|
name: string,
|
||||||
autoIncrement: boolean,
|
autoIncrement: boolean,
|
||||||
keyPath: string[],
|
keyPath?: string[],
|
||||||
records: {
|
records: {
|
||||||
key: string,
|
key?: string,
|
||||||
value: string,
|
value: string,
|
||||||
}[],
|
}[],
|
||||||
indexes: {
|
indexes: {
|
||||||
|
|
|
||||||
|
|
@ -235,14 +235,14 @@ IndexedDBDatabase:
|
||||||
name: string
|
name: string
|
||||||
autoIncrement: boolean
|
autoIncrement: boolean
|
||||||
keyPath:
|
keyPath:
|
||||||
type: array
|
type: array?
|
||||||
items: string
|
items: string
|
||||||
records:
|
records:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
key: string
|
key: string?
|
||||||
value: string
|
value: string
|
||||||
indexes:
|
indexes:
|
||||||
type: array
|
type: array
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,6 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
|
||||||
keyPath: ['taskTitle'],
|
keyPath: ['taskTitle'],
|
||||||
records: [
|
records: [
|
||||||
{
|
{
|
||||||
key: 'Pet the cat',
|
|
||||||
value: JSON.stringify({
|
value: JSON.stringify({
|
||||||
taskTitle: 'Pet the cat',
|
taskTitle: 'Pet the cat',
|
||||||
hours: '1',
|
hours: '1',
|
||||||
|
|
@ -408,3 +407,63 @@ it('should support IndexedDB', async ({ page, contextFactory }) => {
|
||||||
- text: /Pet the cat/
|
- text: /Pet the cat/
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('indexedDb firebase acceptance test', async ({ page, contextFactory }) => {
|
||||||
|
await page.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
||||||
|
await page.getByText('Continue as guest').click();
|
||||||
|
await expect(page.locator('#user-info')).toMatchAriaSnapshot(`
|
||||||
|
- text: New User
|
||||||
|
`);
|
||||||
|
await page.close();
|
||||||
|
const storageState = await page.context().storageState();
|
||||||
|
expect(storageState).toEqual({
|
||||||
|
'cookies': [],
|
||||||
|
'origins': [
|
||||||
|
{
|
||||||
|
'indexedDB': [
|
||||||
|
{
|
||||||
|
'name': 'firebase-heartbeat-database',
|
||||||
|
'stores': [
|
||||||
|
{
|
||||||
|
'autoIncrement': false,
|
||||||
|
'indexes': [],
|
||||||
|
'name': 'firebase-heartbeat-store',
|
||||||
|
'records': [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'version': 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'firebaseLocalStorageDb',
|
||||||
|
'stores': [
|
||||||
|
{
|
||||||
|
'autoIncrement': false,
|
||||||
|
'indexes': [],
|
||||||
|
'keyPath': [
|
||||||
|
'fbase_key',
|
||||||
|
],
|
||||||
|
'name': 'firebaseLocalStorage',
|
||||||
|
'records': [
|
||||||
|
{
|
||||||
|
'value': expect.any(String),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'version': 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'localStorage': [],
|
||||||
|
'origin': 'https://fir-ui-demo-84a6c.firebaseapp.com',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const recreatedContext = await contextFactory({ storageState });
|
||||||
|
const recreatedPage = await recreatedContext.newPage();
|
||||||
|
await recreatedPage.goto('https://fir-ui-demo-84a6c.firebaseapp.com/');
|
||||||
|
expect(await recreatedContext.storageState()).toEqual(storageState);
|
||||||
|
await expect(recreatedPage.locator('body')).toMatchAriaSnapshot(`
|
||||||
|
- text: New User
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue