chore: pretty print storage state (#5830)
This commit is contained in:
parent
c2db8da4df
commit
5cf13612cf
|
|
@ -232,7 +232,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
|
|||
const state = await channel.storageState();
|
||||
if (options.path) {
|
||||
await mkdirIfNeeded(options.path);
|
||||
await fsWriteFileAsync(options.path, JSON.stringify(state), 'utf8');
|
||||
await fsWriteFileAsync(options.path, JSON.stringify(state, undefined, 2), 'utf8');
|
||||
}
|
||||
return state;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -314,13 +314,14 @@ export abstract class BrowserContext extends SdkObject {
|
|||
});
|
||||
for (const origin of this._origins) {
|
||||
const originStorage: types.OriginStorage = { origin, localStorage: [] };
|
||||
result.origins.push(originStorage);
|
||||
const frame = page.mainFrame();
|
||||
await frame.goto(internalMetadata, origin);
|
||||
const storage = await frame._evaluateExpression(`({
|
||||
localStorage: Object.keys(localStorage).map(name => ({ name, value: localStorage.getItem(name) })),
|
||||
})`, false, undefined, 'utility');
|
||||
originStorage.localStorage = storage.localStorage;
|
||||
if (storage.localStorage.length)
|
||||
result.origins.push(originStorage);
|
||||
}
|
||||
await page.close(internalMetadata);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ it('should round-trip through the file', async ({ browser, context, testInfo })
|
|||
const path = testInfo.outputPath('storage-state.json');
|
||||
const state = await context.storageState({ path });
|
||||
const written = await fs.promises.readFile(path, 'utf8');
|
||||
expect(JSON.stringify(state)).toBe(written);
|
||||
expect(JSON.stringify(state, undefined, 2)).toBe(written);
|
||||
|
||||
const context2 = await browser.newContext({ storageState: path });
|
||||
const page2 = await context2.newPage();
|
||||
|
|
|
|||
Loading…
Reference in a new issue