|
13 | 13 | <p>This page verifies that script overloading works <a href="../config/script-overload.json">config</a></p>
|
14 | 14 |
|
15 | 15 | <script>
|
16 |
| - test('Script should have generic overloaded changes', async () => { |
| 16 | + test('Script should have generic overloaded localStorage changes', async () => { |
17 | 17 | // @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
|
18 | 18 | window.scriptOutput = false;
|
19 | 19 | window.scriptyRan = false;
|
20 | 20 | const scriptElement = document.createElement('script');
|
21 |
| - scriptElement.src = './../../shared/replay.js'; |
| 21 | + // TODO fix with some URL injection import (needs to be a different URL than the tab) |
| 22 | + scriptElement.src = `http://localhost:${window.location.port}/shared/replay.js`; |
22 | 23 | scriptElement.id = 'overloadedScript';
|
23 | 24 | let resolver
|
24 | 25 | const promise = new Promise((resolve) => {
|
|
29 | 30 | }
|
30 | 31 | document.body.appendChild(scriptElement);
|
31 | 32 | await promise
|
32 |
| - console.log(window.scriptyRan, window.replayScript) |
33 | 33 | localStorage.clear()
|
34 | 34 | replayScript(`
|
35 | 35 | localStorage.clear();
|
36 | 36 | localStorage.setItem('test', 'test');
|
| 37 | + localStorage.other = "test"; |
37 | 38 | window.scriptyRan = true;
|
38 | 39 | window.scriptOutput = {
|
39 |
| - item: localStorage.getItem('test') |
| 40 | + item: localStorage.getItem('test'), |
| 41 | + other: localStorage.getItem('other'), |
40 | 42 | }
|
41 | 43 | `)
|
42 |
| - |
43 | 44 | const scripty = document.querySelector('script#overloadedScript');
|
44 | 45 | const nodeAndFakeNodeMatch = scripty === scriptElement;
|
45 | 46 |
|
46 | 47 | return [
|
47 | 48 | { name: 'script ran', result: window.scriptyRan, expected: true },
|
48 | 49 | { name: 'node and fake node match', result: nodeAndFakeNodeMatch, expected: false },
|
49 | 50 | { name: 'expected localStorage first response', result: window.scriptOutput, expected: {
|
50 |
| - item: 'test' |
| 51 | + item: 'test', |
| 52 | + other: 'test' |
| 53 | + }}, |
| 54 | + { name: 'did not globally store', result: localStorage.getItem('test'), expected: null }, |
| 55 | + { name: 'did session store', result: sessionStorage.getItem('test'), expected: 'test' }, |
| 56 | + ]; |
| 57 | + }); |
| 58 | + |
| 59 | + test('Script should have generic overloaded sessionStorage changes', async () => { |
| 60 | + // @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f |
| 61 | + window.script2Output = false; |
| 62 | + const scriptElement = document.createElement('script'); |
| 63 | + // TODO fix with some URL injection import (needs to be a different URL than the tab) |
| 64 | + scriptElement.src = `http://localhost:${window.location.port}/shared/replay.js`; |
| 65 | + scriptElement.id = 'overloadedScript2'; |
| 66 | + let resolver |
| 67 | + const promise = new Promise((resolve) => { |
| 68 | + resolver = resolve |
| 69 | + }) |
| 70 | + scriptElement.onload = () => { |
| 71 | + resolver() |
| 72 | + } |
| 73 | + document.body.appendChild(scriptElement); |
| 74 | + await promise |
| 75 | + sessionStorage.clear() |
| 76 | + replayScript(` |
| 77 | + sessionStorage.clear(); |
| 78 | + sessionStorage.setItem('test', 'test'); |
| 79 | + sessionStorage.other = "test"; |
| 80 | + window.script2Output = { |
| 81 | + item: sessionStorage.getItem('test'), |
| 82 | + other: sessionStorage.getItem('other'), |
| 83 | + } |
| 84 | + `) |
| 85 | + const scripty = document.querySelector('script#overloadedScript'); |
| 86 | + const nodeAndFakeNodeMatch = scripty === scriptElement; |
| 87 | + |
| 88 | + return [ |
| 89 | + { name: 'script ran', result: !!window.script2Output, expected: true }, |
| 90 | + { name: 'node and fake node match', result: nodeAndFakeNodeMatch, expected: false }, |
| 91 | + { name: 'expected localStorage first response', result: window.script2Output, expected: { |
| 92 | + item: 'test', |
| 93 | + other: 'test' |
51 | 94 | }},
|
52 |
| - { name: 'did not globally store', result: localStorage.getItem('test'), expected: null } |
| 95 | + { name: 'did not globally store', result: localStorage.getItem('test'), expected: null }, |
| 96 | + { name: 'did session store', result: sessionStorage.getItem('test'), expected: null }, |
53 | 97 | ];
|
54 | 98 | });
|
55 | 99 |
|
|
0 commit comments