Skip to content

Commit 3f79555

Browse files
committed
Update unit/platform tests
1 parent 75a9888 commit 3f79555

File tree

2 files changed

+64
-94
lines changed

2 files changed

+64
-94
lines changed

glean/tests/unit/platform/browser/web/platform_info.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import assert from "assert";
66

7-
import { KnownOperatingSystems } from "../../../../../src/core/platform_info/shared";
7+
import { KnownOperatingSystems } from "../../../../../src/core/platform_info";
88
import PlatformInfo from "../../../../../src/platform/browser/web/platform_info";
99

1010
describe("PlatformInfo/browser/web", function () {

glean/tests/unit/platform/storage.spec.ts

Lines changed: 63 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
import assert from "assert";
66
import "fake-indexeddb/auto";
77

8-
import type Store from "../../../src/core/storage/async";
9-
import type { OptionalAsync } from "../../../src/core/types";
8+
import type Store from "../../../src/core/storage.js";
109
import type { JSONValue } from "../../../src/core/utils";
1110

1211
import TestStore from "../../../src/platform/test/storage";
1312
import { isUndefined } from "../../../src/core/utils";
1413

15-
16-
// This object will contain all the asynchronous store names and
17-
// a function that will initialize and return the store when done.
18-
const asyncStores: {
14+
const stores: {
1915
[store: string]: {
20-
initializeStore: () => OptionalAsync<Store>,
16+
initializeStore: () => Store,
2117
before?: () => Promise<void>,
2218
afterAll?: () => Promise<void>
2319
}
@@ -27,8 +23,8 @@ const asyncStores: {
2723
}
2824
};
2925

30-
for (const store in asyncStores) {
31-
const currentStore = asyncStores[store];
26+
for (const store in stores) {
27+
const currentStore = stores[store];
3228

3329
describe(`storage/${store}`, function () {
3430
after(async function () {
@@ -56,44 +52,44 @@ for (const store in asyncStores) {
5652

5753
before(async function () {
5854
!isUndefined(currentStore.before) && await currentStore.before();
59-
store = await currentStore.initializeStore();
60-
await store.update(["bip", "bling"], () => false);
61-
await store.update(["bip", "bop", "blip"], () => "something, something!");
62-
await store.update(["bip", "bop", "blergh"], () => "don't panic!");
63-
await store.update(["bip", "bop", "burp"], () => "you are doing great!");
64-
await store.update(["bip", "boing"], () => "almost done!");
65-
await store.update(["bip", "bok", "blot"], () => "smile!");
66-
await store.update(["bip", "bok", "bet"], () => "this is the end!");
67-
await store.update(["bump"], () => "not quite!");
68-
});
69-
70-
it("Attempting to get the whole store works", async function () {
71-
const value = await store.get();
55+
store = currentStore.initializeStore();
56+
store.update(["bip", "bling"], () => false);
57+
store.update(["bip", "bop", "blip"], () => "something, something!");
58+
store.update(["bip", "bop", "blergh"], () => "don't panic!");
59+
store.update(["bip", "bop", "burp"], () => "you are doing great!");
60+
store.update(["bip", "boing"], () => "almost done!");
61+
store.update(["bip", "bok", "blot"], () => "smile!");
62+
store.update(["bip", "bok", "bet"], () => "this is the end!");
63+
store.update(["bump"], () => "not quite!");
64+
});
65+
66+
it("Attempting to get the whole store works", function () {
67+
const value = store.get();
7268
assert.deepStrictEqual(value, expected);
7369
});
7470

75-
it("Attempting to get a non-existent entry doesn't error", async function () {
76-
const value = await store.get(["random", "inexistent", "index"]);
71+
it("Attempting to get a non-existent entry doesn't error", function () {
72+
const value = store.get(["random", "inexistent", "index"]);
7773
assert.strictEqual(value, undefined);
7874
});
7975

80-
it("Attempting to get a non-existent nested entry works", async function () {
81-
const value = await store.get(["bip", "bop", "inexistent"]);
76+
it("Attempting to get a non-existent nested entry works", function () {
77+
const value = store.get(["bip", "bop", "inexistent"]);
8278
assert.strictEqual(value, undefined);
8379
});
8480

85-
it("Attempting to get an index that contains an object works", async function () {
86-
const value = await store.get(["bip", "bok"]);
81+
it("Attempting to get an index that contains an object works", function () {
82+
const value = store.get(["bip", "bok"]);
8783
assert.deepStrictEqual(value, expected["bip"]["bok"]);
8884
});
8985

90-
it("Attempting to get an index that contains a string works", async function () {
91-
const value = await store.get(["bump"]);
86+
it("Attempting to get an index that contains a string works", function () {
87+
const value = store.get(["bump"]);
9288
assert.deepStrictEqual(value, expected["bump"]);
9389
});
9490

95-
it("Attempting to get an index that contains a boolean works", async function () {
96-
const value = await store.get(["bip", "bling"]);
91+
it("Attempting to get an index that contains a boolean works", function () {
92+
const value = store.get(["bip", "bling"]);
9793
assert.strictEqual(value, expected["bip"]["bling"]);
9894
});
9995
});
@@ -105,36 +101,33 @@ for (const store in asyncStores) {
105101

106102
before(async function() {
107103
!isUndefined(currentStore.before) && await currentStore.before();
108-
store = await currentStore.initializeStore();
104+
store = currentStore.initializeStore();
109105
});
110106

111-
it("Attempting to update a non-existent entry works", async function () {
112-
await store.update(index, () => value);
113-
assert.strictEqual(value, await store.get(index));
107+
it("Attempting to update a non-existent entry works", function () {
108+
store.update(index, () => value);
109+
assert.strictEqual(value, store.get(index));
114110
});
115111

116-
it("Attempting to update an existing entry doesn't error ", async function () {
112+
it("Attempting to update an existing entry doesn't error ", function () {
117113
const updater = (v?: JSONValue): string => `${JSON.stringify(v)} new and improved!`;
118-
await store.update(index, updater);
119-
assert.strictEqual(updater(value), await store.get(index));
114+
store.update(index, updater);
115+
assert.strictEqual(updater(value), store.get(index));
120116
});
121117

122-
it("Attempting to update a nested entry doesn't error and overwrites", async function () {
118+
it("Attempting to update a nested entry doesn't error and overwrites", function () {
123119
const updatedIndex = index.slice(1);
124-
await store.update(updatedIndex, () => value);
125-
assert.strictEqual(value, await store.get(updatedIndex));
120+
store.update(updatedIndex, () => value);
121+
assert.strictEqual(value, store.get(updatedIndex));
126122
});
127123

128124
it("Attempting to update an empty index throws an error", function () {
129-
store
130-
.update([], () => "should never get here!")
131-
.then(() =>
132-
assert.ok(
133-
false,
134-
"Attempting to update with an empty index should fail."
135-
)
136-
)
137-
.catch(() => assert.ok(true));
125+
try {
126+
store.update([], () => "should never get here!");
127+
assert.ok(false, "Attempting to update with an empty index should fail.");
128+
} catch (e) {
129+
assert.ok(true);
130+
}
138131
});
139132
});
140133

@@ -145,66 +138,43 @@ for (const store in asyncStores) {
145138

146139
before(async function() {
147140
!isUndefined(currentStore.before) && await currentStore.before();
148-
store = await currentStore.initializeStore();
141+
store = currentStore.initializeStore();
149142
});
150143

151-
it("Attempting to delete an existing index works", async function () {
152-
await store.update(index, () => value);
153-
assert.strictEqual(value, await store.get(index));
144+
it("Attempting to delete an existing index works", function () {
145+
store.update(index, () => value);
146+
assert.strictEqual(value, store.get(index));
154147

155-
await store.delete(index);
156-
assert.strictEqual(await store.get(index), undefined);
148+
store.delete(index);
149+
assert.strictEqual(store.get(index), undefined);
157150
});
158151

159-
it("Attempting to delete a non-existing entry is a no-op", async function () {
160-
await store.update(index, () => value);
161-
const storeSnapshot = await store.get();
152+
it("Attempting to delete a non-existing entry is a no-op", function () {
153+
store.update(index, () => value);
154+
const storeSnapshot = store.get();
162155

163-
await store.delete(["random", "inexistent", "index"]);
156+
store.delete(["random", "inexistent", "index"]);
164157
assert.deepStrictEqual(
165158
storeSnapshot,
166-
await store.get()
159+
store.get()
167160
);
168161
});
169162

170-
it("Attempting to delete an index that is not correct is a no-op", async function () {
171-
await store.update(index, () => value);
172-
const storeSnapshot = await store.get();
163+
it("Attempting to delete an index that is not correct is a no-op", function () {
164+
store.update(index, () => value);
165+
const storeSnapshot = store.get();
173166

174-
await store.delete(index.slice(1));
167+
store.delete(index.slice(1));
175168
assert.deepStrictEqual(
176169
storeSnapshot,
177-
await store.get()
170+
store.get()
178171
);
179172
});
180173

181-
it("Attempting to delete an empty index deletes all entries in the store", async function () {
182-
await store.delete([]);
183-
assert.deepStrictEqual(undefined, await store.get());
174+
it("Attempting to delete an empty index deletes all entries in the store", function () {
175+
store.delete([]);
176+
assert.deepStrictEqual(undefined, store.get());
184177
});
185178
});
186179
});
187180
}
188-
189-
// TODO
190-
// Write tests for the synchronous store. `LocalStorage` does not exist by default,
191-
// so it needs to be mocked instead, like we do for QML.
192-
//
193-
// This object will contain all the synchronous store names and
194-
// a function that will initialize and return the store when done.
195-
// const syncStores: {
196-
// [store: string]: {
197-
// initializeStore: () => SynchronousStore;
198-
// before?: () => void;
199-
// afterAll?: () => void;
200-
// };
201-
// } = {
202-
// WebStore: {
203-
// initializeStore: (): WebStore => {
204-
// const store = new WebStore("test");
205-
// // Clear the store before starting.
206-
// store.delete([]);
207-
// return store;
208-
// }
209-
// }
210-
// };

0 commit comments

Comments
 (0)