mirror of
https://github.com/maputnik/editor.git
synced 2026-08-25 06:27:25 +00:00
Move fill local storage to driver
This commit is contained in:
@@ -493,6 +493,31 @@ export class MaputnikDriver {
|
|||||||
waitForExampleFileResponse: () => this.when.waitForResponse("example-style.json"),
|
waitForExampleFileResponse: () => this.when.waitForResponse("example-style.json"),
|
||||||
|
|
||||||
clearLocalStorage: () => this.page.evaluate(() => window.localStorage.clear()),
|
clearLocalStorage: () => this.page.evaluate(() => window.localStorage.clear()),
|
||||||
|
|
||||||
|
/** fill localStorage until we get a QuotaExceededError */
|
||||||
|
fillLocalStorage: async () => {
|
||||||
|
await this.page.evaluate(() => {
|
||||||
|
let chunkSize = 1000;
|
||||||
|
const chunk = new Array(chunkSize).join("x");
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
// Keep adding until we hit the quota
|
||||||
|
for (;;) {
|
||||||
|
try {
|
||||||
|
const key = `maputnik:fill-${index++}`;
|
||||||
|
window.localStorage.setItem(key, chunk);
|
||||||
|
} catch (e: any) {
|
||||||
|
// Verify it's a quota error
|
||||||
|
if (e.name === "QuotaExceededError") {
|
||||||
|
if (chunkSize <= 1) return;
|
||||||
|
chunkSize /= 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw e; // Unexpected error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---- get -----------------------------------------------------------------
|
// ---- get -----------------------------------------------------------------
|
||||||
|
|||||||
+1
-23
@@ -391,29 +391,7 @@ describe("modals", () => {
|
|||||||
test("handles quota exceeded error when opening style from URL", async ({ page }) => {
|
test("handles quota exceeded error when opening style from URL", async ({ page }) => {
|
||||||
// Clear localStorage to start fresh
|
// Clear localStorage to start fresh
|
||||||
await when.clearLocalStorage();
|
await when.clearLocalStorage();
|
||||||
|
await when.fillLocalStorage();
|
||||||
// fill localStorage until we get a QuotaExceededError
|
|
||||||
await page.evaluate(() => {
|
|
||||||
let chunkSize = 1000;
|
|
||||||
const chunk = new Array(chunkSize).join("x");
|
|
||||||
let index = 0;
|
|
||||||
|
|
||||||
// Keep adding until we hit the quota
|
|
||||||
for (;;) {
|
|
||||||
try {
|
|
||||||
const key = `maputnik:fill-${index++}`;
|
|
||||||
window.localStorage.setItem(key, chunk);
|
|
||||||
} catch (e: any) {
|
|
||||||
// Verify it's a quota error
|
|
||||||
if (e.name === "QuotaExceededError") {
|
|
||||||
if (chunkSize <= 1) return;
|
|
||||||
chunkSize /= 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
throw e; // Unexpected error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Open the style via URL input
|
// Open the style via URL input
|
||||||
await when.click("nav:open");
|
await when.click("nav:open");
|
||||||
|
|||||||
Reference in New Issue
Block a user