Skip to content

Commit 06067e3

Browse files
committed
test: add coverage for webstorage quota
1 parent cf8e535 commit 06067e3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/parallel/test-webstorage.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,39 @@ test('localStorage is persisted if it is used', async () => {
109109
assert.strictEqual(cp.code, 0);
110110
assert.match(cp.stdout, /barbaz/);
111111
});
112+
113+
test('localStorage can store and retrieve a max of 10 MB quota', async () => {
114+
const localStorageFile = nextLocalStorage();
115+
const cpToFill = await spawnPromisified(process.execPath, [
116+
'--experimental-webstorage',
117+
'--localstorage-file', localStorageFile,
118+
// Each character is 2 bytes
119+
'-pe', `for (let i = 0; i < 10; i++) {
120+
localStorage[i.toString().repeat(1 * 1024 * 1024 / 2)] = '';
121+
}
122+
`,
123+
]);
124+
const cpToVerify = await spawnPromisified(process.execPath, [
125+
'--experimental-webstorage',
126+
'--localstorage-file', localStorageFile,
127+
'-pe', `localStorage.anything = 'should fail';`,
128+
]);
129+
130+
assert.doesNotMatch(cpToFill.stderr, /QuotaExceededError/);
131+
assert.match(cpToVerify.stderr, /QuotaExceededError: Setting the value exceeded the quota/);
132+
});
133+
134+
test('sessionStorage can store a max of 10 MB quota', async () => {
135+
const cpToFill = await spawnPromisified(process.execPath, [
136+
'--experimental-webstorage',
137+
// Each character is 2 bytes
138+
'-pe', `for (let i = 0; i < 10; i++) {
139+
sessionStorage[i.toString().repeat(1 * 1024 * 1024 / 2)] = '';
140+
}
141+
142+
sessionStorage.anything = 'should fail';
143+
`,
144+
]);
145+
146+
assert.match(cpToFill.stderr, /QuotaExceededError/);
147+
});

0 commit comments

Comments
 (0)