|
2 | 2 |
|
3 | 3 | (function () {
|
4 | 4 |
|
5 |
| - let BACKUP = {}; |
6 |
| - |
7 |
| - QUnit.config.autostart = false; |
8 |
| - QUnit.config.testTimeout = 6400; |
9 |
| - |
10 |
| - // disable storage persistence |
11 |
| - // unit tests shouldn't be able to affect your Badger's storage |
12 |
| - chrome.storage.local.set = () => {}; |
13 |
| - |
14 |
| - // make it seem like there is nothing in storage |
15 |
| - // unit tests shouldn't read from your Badger's storage either |
16 |
| - chrome.storage.local.get = (keys, callback) => { |
17 |
| - // callback has to be async |
18 |
| - setTimeout(function () { |
19 |
| - callback({ |
20 |
| - // don't open the new user intro page or load seed data |
21 |
| - settings_map: { |
22 |
| - isFirstRun: false, |
23 |
| - } |
24 |
| - }); |
25 |
| - }, 0); |
26 |
| - }; |
27 |
| - |
28 |
| - // reset state between tests |
29 |
| - // to prevent tests affecting each other via side effects |
30 |
| - QUnit.testStart(() => { |
31 |
| - // back up settings and heuristic learning |
32 |
| - // TODO any other state we should reset? tabData? |
33 |
| - badger.storage.KEYS.forEach(item => { |
34 |
| - let obj = badger.storage.getBadgerStorageObject(item); |
35 |
| - BACKUP[item] = obj.getItemClones(); |
| 5 | +let BACKUP = {}; |
| 6 | + |
| 7 | +QUnit.config.autostart = false; |
| 8 | +QUnit.config.testTimeout = 6400; |
| 9 | + |
| 10 | +// disable storage persistence |
| 11 | +// unit tests shouldn't be able to affect your Badger's storage |
| 12 | +chrome.storage.local.set = () => {}; |
| 13 | + |
| 14 | +// make it seem like there is nothing in storage |
| 15 | +// unit tests shouldn't read from your Badger's storage either |
| 16 | +chrome.storage.local.get = (keys, callback) => { |
| 17 | + // callback has to be async |
| 18 | + setTimeout(function () { |
| 19 | + callback({ |
| 20 | + // don't open the new user intro page or load seed data |
| 21 | + settings_map: { |
| 22 | + isFirstRun: false, |
| 23 | + } |
36 | 24 | });
|
| 25 | + }, 0); |
| 26 | +}; |
| 27 | + |
| 28 | +// reset state between tests |
| 29 | +// to prevent tests affecting each other via side effects |
| 30 | +QUnit.testStart(() => { |
| 31 | + // back up settings and heuristic learning |
| 32 | + // TODO any other state we should reset? tabData? |
| 33 | + badger.storage.KEYS.forEach(item => { |
| 34 | + let obj = badger.storage.getBadgerStorageObject(item); |
| 35 | + BACKUP[item] = obj.getItemClones(); |
37 | 36 | });
|
| 37 | +}); |
38 | 38 |
|
39 |
| - QUnit.testDone(() => { |
40 |
| - // restore original settings and heuristic learning |
41 |
| - badger.storage.KEYS.forEach(item => { |
42 |
| - let obj = badger.storage.getBadgerStorageObject(item); |
43 |
| - obj.updateObject(BACKUP[item]); |
44 |
| - }); |
| 39 | +QUnit.testDone(() => { |
| 40 | + // restore original settings and heuristic learning |
| 41 | + badger.storage.KEYS.forEach(item => { |
| 42 | + let obj = badger.storage.getBadgerStorageObject(item); |
| 43 | + obj.updateObject(BACKUP[item]); |
45 | 44 | });
|
| 45 | +}); |
46 | 46 |
|
47 |
| - // kick off tests when we have what we need from Badger |
48 |
| - (function () { |
| 47 | +// kick off tests when we have what we need from Badger |
| 48 | +(function () { |
49 | 49 |
|
50 |
| - function get_storage_length(store) { |
51 |
| - return Object.keys( |
52 |
| - badger.storage.getBadgerStorageObject(store).getItemClones() |
53 |
| - ).length; |
54 |
| - } |
| 50 | + function get_storage_length(store) { |
| 51 | + return Object.keys( |
| 52 | + badger.storage.getBadgerStorageObject(store).getItemClones() |
| 53 | + ).length; |
| 54 | + } |
55 | 55 |
|
56 |
| - const WAIT_INTERVAL = 10, |
57 |
| - MAX_WAIT = 1000; |
| 56 | + const WAIT_INTERVAL = 10, |
| 57 | + MAX_WAIT = 1000; |
58 | 58 |
|
59 |
| - let elapsed = 0; |
| 59 | + let elapsed = 0; |
60 | 60 |
|
61 |
| - function wait_for_badger() { |
62 |
| - elapsed += WAIT_INTERVAL; |
| 61 | + function wait_for_badger() { |
| 62 | + elapsed += WAIT_INTERVAL; |
63 | 63 |
|
64 |
| - if (elapsed >= MAX_WAIT) { |
65 |
| - // give up |
66 |
| - QUnit.start(); |
67 |
| - } |
| 64 | + if (elapsed >= MAX_WAIT) { |
| 65 | + // give up |
| 66 | + QUnit.start(); |
| 67 | + } |
68 | 68 |
|
69 |
| - if (typeof badger == "object" && badger.INITIALIZED && |
70 |
| - // TODO have badger.INITIALIZED account |
71 |
| - // for things getting initialized async |
72 |
| - !!get_storage_length('dnt_hashes') && |
73 |
| - !!get_storage_length('cookieblock_list') |
74 |
| - ) { |
75 |
| - QUnit.start(); |
76 |
| - } else { |
77 |
| - setTimeout(wait_for_badger, WAIT_INTERVAL); |
78 |
| - } |
| 69 | + if (typeof badger == "object" && badger.INITIALIZED && |
| 70 | + // TODO have badger.INITIALIZED account |
| 71 | + // for things getting initialized async |
| 72 | + !!get_storage_length('dnt_hashes') && |
| 73 | + !!get_storage_length('cookieblock_list') |
| 74 | + ) { |
| 75 | + QUnit.start(); |
| 76 | + } else { |
| 77 | + setTimeout(wait_for_badger, WAIT_INTERVAL); |
79 | 78 | }
|
| 79 | + } |
80 | 80 |
|
81 |
| - setTimeout(wait_for_badger, WAIT_INTERVAL); |
| 81 | + setTimeout(wait_for_badger, WAIT_INTERVAL); |
82 | 82 |
|
83 |
| - }()); |
| 83 | +}()); |
84 | 84 |
|
85 | 85 | }());
|
0 commit comments