| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9b24a81 commit 48a3ca3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,7 @@ export default [ | |||
| 70 | 70 | // Filtering tsc output files (i.e. if there a foo.ts, we ignore foo.js): | |
| 71 | 71 | (f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts')), | |
| 72 | 72 | ), | |
| 73 | + '!test/fixtures/test-inspector-dom-storage.mjs', | ||
| 73 | 74 | '!test/fixtures/test-runner', | |
| 74 | 75 | 'test/fixtures/test-runner/*', | |
| 75 | 76 | '!test/fixtures/test-runner/output', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,151 @@ | |||
| 1 | + import * as common from '../common/index.mjs'; | ||
| 2 | + import assert from 'assert'; | ||
| 3 | + import { DOMStorage, Session } from 'node:inspector/promises'; | ||
| 4 | + import { pathToFileURL } from 'node:url'; | ||
| 5 | + import path from 'node:path'; | ||
| 6 | + import process from 'node:process'; | ||
| 7 | + | ||
| 8 | + { | ||
| 9 | + const session = new Session(); | ||
| 10 | + await session.connect(); | ||
| 11 | + | ||
| 12 | + await session.post('DOMStorage.enable'); | ||
| 13 | + | ||
| 14 | + const localStorageFileUrl = | ||
| 15 | + pathToFileURL(path.join(process.cwd(), 'localstorage.db')).href; | ||
| 16 | + | ||
| 17 | + const { storageKey } = await session.post('Storage.getStorageKey'); | ||
| 18 | + assert.strictEqual( | ||
| 19 | + storageKey.toLowerCase(), | ||
| 20 | + localStorageFileUrl.toLowerCase(), | ||
| 21 | + ); | ||
| 22 | + | ||
| 23 | + for (const isLocalStorage of [true, false]) { | ||
| 24 | + DOMStorage.registerStorage({ | ||
| 25 | + isLocalStorage, | ||
| 26 | + storageMap: { | ||
| 27 | + key1: 'value1', | ||
| 28 | + key2: 'value2', | ||
| 29 | + [1]: 2, | ||
| 30 | + [true]: 'booleanKey', | ||
| 31 | + ['ключ']: 'значение', | ||
| 32 | + }, | ||
| 33 | + }); | ||
| 34 | + const result = await session.post('DOMStorage.getDOMStorageItems', { | ||
| 35 | + storageId: { | ||
| 36 | + isLocalStorage, | ||
| 37 | + securityOrigin: 'node-inspector://default-dom-storage', | ||
| 38 | + }, | ||
| 39 | + }); | ||
| 40 | + const sortedEntries = result.entries.sort((a, b) => | ||
| 41 | + a[0].localeCompare(b[0]), | ||
| 42 | + ); | ||
| 43 | + assert.deepStrictEqual(sortedEntries, [ | ||
| 44 | + ['1', '2'], | ||
| 45 | + ['key1', 'value1'], | ||
| 46 | + ['key2', 'value2'], | ||
| 47 | + ['true', 'booleanKey'], | ||
| 48 | + ['ключ', 'значение'], | ||
| 49 | + ]); | ||
| 50 | + } | ||
| 51 | + session.disconnect(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + { | ||
| 55 | + for (const isLocalStorage of [true, false]) { | ||
| 56 | + const webStorage = isLocalStorage ? localStorage : sessionStorage; | ||
| 57 | + const session = new Session(); | ||
| 58 | + webStorage.clear(); | ||
| 59 | + await session.connect(); | ||
| 60 | + | ||
| 61 | + const storageKey = await session.post('Storage.getStorageKey'); | ||
| 62 | + await session.post('DOMStorage.enable'); | ||
| 63 | + | ||
| 64 | + webStorage.setItem('key1', 'value'); | ||
| 65 | + webStorage.setItem('key2', 1); | ||
| 66 | + webStorage.setItem('key3', JSON.stringify({ a: 1 })); | ||
| 67 | + webStorage.setItem('ключ', 'значение'); | ||
| 68 | + | ||
| 69 | + const result = await session.post('DOMStorage.getDOMStorageItems', { | ||
| 70 | + storageId: { | ||
| 71 | + isLocalStorage, | ||
| 72 | + securityOrigin: '', | ||
| 73 | + storageKey: storageKey.storageKey, | ||
| 74 | + }, | ||
| 75 | + }); | ||
| 76 | + assert.strictEqual(result.entries.length, 4); | ||
| 77 | + const entries = Object.fromEntries(result.entries); | ||
| 78 | + assert.strictEqual(entries.key1, 'value'); | ||
| 79 | + assert.strictEqual(entries.key2, '1'); | ||
| 80 | + assert.strictEqual(entries.key3, JSON.stringify({ a: 1 })); | ||
| 81 | + assert.strictEqual(entries['ключ'], 'значение'); | ||
| 82 | + session.disconnect(); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + { | ||
| 87 | + for (const isLocalStorage of [true, false]) { | ||
| 88 | + const webStorage = isLocalStorage ? localStorage : sessionStorage; | ||
| 89 | + webStorage.clear(); | ||
| 90 | + const session = new Session(); | ||
| 91 | + await session.connect(); | ||
| 92 | + await session.post('DOMStorage.enable'); | ||
| 93 | + const storageKey = await session.post('Storage.getStorageKey'); | ||
| 94 | + session.on( | ||
| 95 | + 'DOMStorage.domStorageItemAdded', | ||
| 96 | + common.mustCall(({ params }) => { | ||
| 97 | + assert.strictEqual(params.key, 'key'); | ||
| 98 | + assert.strictEqual(params.newValue, 'value'); | ||
| 99 | + assert.deepStrictEqual(params.storageId, { | ||
| 100 | + securityOrigin: '', | ||
| 101 | + isLocalStorage, | ||
| 102 | + storageKey: storageKey.storageKey, | ||
| 103 | + }); | ||
| 104 | + }), | ||
| 105 | + ); | ||
| 106 | + webStorage.setItem('key', 'value'); | ||
| 107 | + | ||
| 108 | + session.on( | ||
| 109 | + 'DOMStorage.domStorageItemUpdated', | ||
| 110 | + common.mustCall(({ params }) => { | ||
| 111 | + assert.strictEqual(params.key, 'key'); | ||
| 112 | + assert.strictEqual(params.oldValue, 'value'); | ||
| 113 | + assert.strictEqual(params.newValue, 'newValue'); | ||
| 114 | + assert.deepStrictEqual(params.storageId, { | ||
| 115 | + securityOrigin: '', | ||
| 116 | + isLocalStorage, | ||
| 117 | + storageKey: storageKey.storageKey, | ||
| 118 | + }); | ||
| 119 | + }), | ||
| 120 | + ); | ||
| 121 | + | ||
| 122 | + webStorage.setItem('key', 'newValue'); | ||
| 123 | + | ||
| 124 | + session.on( | ||
| 125 | + 'DOMStorage.domStorageItemRemoved', | ||
| 126 | + common.mustCall(({ params }) => { | ||
| 127 | + assert.strictEqual(params.key, 'key'); | ||
| 128 | + assert.deepStrictEqual(params.storageId, { | ||
| 129 | + securityOrigin: '', | ||
| 130 | + isLocalStorage, | ||
| 131 | + storageKey: storageKey.storageKey, | ||
| 132 | + }); | ||
| 133 | + }), | ||
| 134 | + ); | ||
| 135 | + | ||
| 136 | + webStorage.removeItem('key'); | ||
| 137 | + | ||
| 138 | + session.on( | ||
| 139 | + 'DOMStorage.domStorageItemsCleared', | ||
| 140 | + common.mustCall(({ params }) => { | ||
| 141 | + assert.deepStrictEqual(params.storageId, { | ||
| 142 | + securityOrigin: '', | ||
| 143 | + isLocalStorage, | ||
| 144 | + storageKey: storageKey.storageKey, | ||
| 145 | + }); | ||
| 146 | + }), | ||
| 147 | + ); | ||
| 148 | + webStorage.clear(); | ||
| 149 | + session.disconnect(); | ||
| 150 | + } | ||
| 151 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,170 +1,16 @@ | |||
| 1 | - // Flags: --inspect=0 --experimental-storage-inspection --localstorage-file=./localstorage.db | ||
| 2 | 1 | 'use strict'; | |
| 3 | 2 | ||
| 4 | 3 | const common = require('../common'); | |
| 5 | - const assert = require('assert'); | ||
| 6 | 4 | common.skipIfSQLiteMissing(); | |
| 7 | 5 | common.skipIfInspectorDisabled(); | |
| 8 | - const { DOMStorage, Session } = require('node:inspector/promises'); | ||
| 9 | - const { pathToFileURL } = require('node:url'); | ||
| 10 | - const path = require('node:path'); | ||
| 11 | - | ||
| 12 | - async function testRegisterStorage() { | ||
| 13 | - const session = new Session(); | ||
| 14 | - await session.connect(); | ||
| 15 | - | ||
| 16 | - await session.post('DOMStorage.enable'); | ||
| 17 | - | ||
| 18 | - const localStorageFileUrl = | ||
| 19 | - pathToFileURL(path.join(process.cwd(), 'localstorage.db')).href; | ||
| 20 | - | ||
| 21 | - const { storageKey } = await session.post('Storage.getStorageKey'); | ||
| 22 | - assert.strictEqual( | ||
| 23 | - storageKey.toLowerCase(), | ||
| 24 | - localStorageFileUrl.toLowerCase() | ||
| 25 | - ); | ||
| 26 | - | ||
| 27 | - await checkStorage(true); | ||
| 28 | - await checkStorage(false); | ||
| 29 | - session.disconnect(); | ||
| 30 | - | ||
| 31 | - async function checkStorage(isLocalStorage) { | ||
| 32 | - DOMStorage.registerStorage({ | ||
| 33 | - isLocalStorage, | ||
| 34 | - storageMap: { | ||
| 35 | - key1: 'value1', | ||
| 36 | - key2: 'value2', | ||
| 37 | - [1]: 2, | ||
| 38 | - [true]: 'booleanKey', | ||
| 39 | - ['ключ']: 'значение', | ||
| 40 | - }, | ||
| 41 | - }); | ||
| 42 | - const result = await session.post('DOMStorage.getDOMStorageItems', { | ||
| 43 | - storageId: { | ||
| 44 | - isLocalStorage, | ||
| 45 | - securityOrigin: 'node-inspector://default-dom-storage', | ||
| 46 | - }, | ||
| 47 | - }); | ||
| 48 | - const sortedEntries = result.entries.sort((a, b) => | ||
| 49 | - a[0].localeCompare(b[0]), | ||
| 50 | - ); | ||
| 51 | - assert.deepStrictEqual(sortedEntries, [ | ||
| 52 | - ['1', '2'], | ||
| 53 | - ['key1', 'value1'], | ||
| 54 | - ['key2', 'value2'], | ||
| 55 | - ['true', 'booleanKey'], | ||
| 56 | - ['ключ', 'значение'], | ||
| 57 | - ]); | ||
| 58 | - } | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - async function testGetData() { | ||
| 62 | - await test(true); | ||
| 63 | - await test(false); | ||
| 64 | - | ||
| 65 | - async function test(isLocalStorage) { | ||
| 66 | - const webStorage = isLocalStorage ? localStorage : sessionStorage; | ||
| 67 | - const session = new Session(); | ||
| 68 | - webStorage.clear(); | ||
| 69 | - await session.connect(); | ||
| 70 | - | ||
| 71 | - const storageKey = await session.post('Storage.getStorageKey'); | ||
| 72 | - await session.post('DOMStorage.enable'); | ||
| 73 | - | ||
| 74 | - webStorage.setItem('key1', 'value'); | ||
| 75 | - webStorage.setItem('key2', 1); | ||
| 76 | - webStorage.setItem('key3', JSON.stringify({ a: 1 })); | ||
| 77 | - webStorage.setItem('ключ', 'значение'); | ||
| 78 | - | ||
| 79 | - const result = await session.post('DOMStorage.getDOMStorageItems', { | ||
| 80 | - storageId: { | ||
| 81 | - isLocalStorage, | ||
| 82 | - securityOrigin: '', | ||
| 83 | - storageKey: storageKey.storageKey, | ||
| 84 | - }, | ||
| 85 | - }); | ||
| 86 | - assert.strictEqual(result.entries.length, 4); | ||
| 87 | - const entries = Object.fromEntries(result.entries); | ||
| 88 | - assert.strictEqual(entries.key1, 'value'); | ||
| 89 | - assert.strictEqual(entries.key2, '1'); | ||
| 90 | - assert.strictEqual(entries.key3, JSON.stringify({ a: 1 })); | ||
| 91 | - assert.strictEqual(entries['ключ'], 'значение'); | ||
| 92 | - session.disconnect(); | ||
| 93 | - } | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - async function testEvents() { | ||
| 97 | - await test(true); | ||
| 98 | - await test(false); | ||
| 99 | - async function test(isLocalStorage) { | ||
| 100 | - const webStorage = isLocalStorage ? localStorage : sessionStorage; | ||
| 101 | - webStorage.clear(); | ||
| 102 | - const session = new Session(); | ||
| 103 | - await session.connect(); | ||
| 104 | - await session.post('DOMStorage.enable'); | ||
| 105 | - const storageKey = await session.post('Storage.getStorageKey'); | ||
| 106 | - session.on( | ||
| 107 | - 'DOMStorage.domStorageItemAdded', | ||
| 108 | - common.mustCall(({ params }) => { | ||
| 109 | - assert.strictEqual(params.key, 'key'); | ||
| 110 | - assert.strictEqual(params.newValue, 'value'); | ||
| 111 | - assert.deepStrictEqual(params.storageId, { | ||
| 112 | - securityOrigin: '', | ||
| 113 | - isLocalStorage, | ||
| 114 | - storageKey: storageKey.storageKey, | ||
| 115 | - }); | ||
| 116 | - }), | ||
| 117 | - ); | ||
| 118 | - webStorage.setItem('key', 'value'); | ||
| 119 | - | ||
| 120 | - session.on( | ||
| 121 | - 'DOMStorage.domStorageItemUpdated', | ||
| 122 | - common.mustCall(({ params }) => { | ||
| 123 | - assert.strictEqual(params.key, 'key'); | ||
| 124 | - assert.strictEqual(params.oldValue, 'value'); | ||
| 125 | - assert.strictEqual(params.newValue, 'newValue'); | ||
| 126 | - assert.deepStrictEqual(params.storageId, { | ||
| 127 | - securityOrigin: '', | ||
| 128 | - isLocalStorage, | ||
| 129 | - storageKey: storageKey.storageKey, | ||
| 130 | - }); | ||
| 131 | - }), | ||
| 132 | - ); | ||
| 133 | - | ||
| 134 | - webStorage.setItem('key', 'newValue'); | ||
| 135 | - | ||
| 136 | - session.on( | ||
| 137 | - 'DOMStorage.domStorageItemRemoved', | ||
| 138 | - common.mustCall(({ params }) => { | ||
| 139 | - assert.strictEqual(params.key, 'key'); | ||
| 140 | - assert.deepStrictEqual(params.storageId, { | ||
| 141 | - securityOrigin: '', | ||
| 142 | - isLocalStorage, | ||
| 143 | - storageKey: storageKey.storageKey, | ||
| 144 | - }); | ||
| 145 | - }), | ||
| 146 | - ); | ||
| 147 | - | ||
| 148 | - webStorage.removeItem('key'); | ||
| 149 | - | ||
| 150 | - session.on( | ||
| 151 | - 'DOMStorage.domStorageItemsCleared', | ||
| 152 | - common.mustCall(({ params }) => { | ||
| 153 | - assert.deepStrictEqual(params.storageId, { | ||
| 154 | - securityOrigin: '', | ||
| 155 | - isLocalStorage, | ||
| 156 | - storageKey: storageKey.storageKey, | ||
| 157 | - }); | ||
| 158 | - }), | ||
| 159 | - ); | ||
| 160 | - webStorage.clear(); | ||
| 161 | - session.disconnect(); | ||
| 162 | - } | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | - async function test() { | ||
| 166 | - await testRegisterStorage(); | ||
| 167 | - await testGetData(); | ||
| 168 | - await testEvents(); | ||
| 169 | - } | ||
| 170 | - test().then(common.mustCall()); | ||
| 6 | + const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
| 7 | + const fixtures = require('../common/fixtures'); | ||
| 8 | + const tmpdir = require('../common/tmpdir'); | ||
| 9 | + tmpdir.refresh(); | ||
| 10 | + | ||
| 11 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 12 | + '--inspect=0', | ||
| 13 | + '--experimental-storage-inspection', | ||
| 14 | + '--localstorage-file=./localstorage.db', | ||
| 15 | + fixtures.path('test-inspector-dom-storage.mjs'), | ||
| 16 | + ], { cwd: tmpdir.path }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments