Skip to content

Commit

Permalink
test: add coverage for webstorage quota
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecastelli committed Jul 20, 2024
1 parent cf8e535 commit 7b54022
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/parallel/test-webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,39 @@ test('localStorage is persisted if it is used', async () => {
assert.strictEqual(cp.code, 0);
assert.match(cp.stdout, /barbaz/);
});

test('localStorage can store and retrieve a max of 10 MB quota', async () => {
const localStorageFile = nextLocalStorage();
const cpToFill = await spawnPromisified(process.execPath, [
'--experimental-webstorage',
'--localstorage-file', localStorageFile,
// Each character is 2 bytes
'-pe', `for (let i = 0; i < 10; i++) {
localStorage[i.toString().repeat(1 * 1024 * 1024 / 2)] = '';
}
`,
]);
const cpToVerify = await spawnPromisified(process.execPath, [
'--experimental-webstorage',
'--localstorage-file', localStorageFile,
'-pe', `localStorage.largeKey = 'anything';`,
]);

assert.doesNotMatch(cpToFill.stderr, /QuotaExceededError/);
assert.match(cpToVerify.stderr, /QuotaExceededError: Setting the value exceeded the quota/);
});

test('sessionStorage can store a max of 10 MB quota', async () => {
const cpToFill = await spawnPromisified(process.execPath, [
'--experimental-webstorage',
// Each character is 2 bytes
'-pe', `for (let i = 0; i < 10; i++) {
sessionStorage[i.toString().repeat(1 * 1024 * 1024 / 2)] = '';
}
sessionStorage['anything'] = '';
`,
]);

assert.match(cpToFill.stderr, /QuotaExceededError/);
});

Check failure on line 147 in test/parallel/test-webstorage.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Newline required at end of file but not found

0 comments on commit 7b54022

Please sign in to comment.