Skip to content

Commit b822461

Browse files
committed
Add Google verification meta tag and stabilize localStorage tests
1 parent dda79b0 commit b822461

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
content="c4Lab builds computational solutions for genomics, immunogenomics, and precision medicine at National Taiwan University."
99
/>
1010
<meta name="robots" content="index, follow" />
11+
<meta name="google-site-verification" content="tSaDTD0QDgmtcYQ4fwCHLghu-7J9kv_b7ri4QhoW24w" />
1112
<link rel="canonical" href="https://c4lab.github.io/" />
1213
<meta property="og:type" content="website" />
1314
<meta property="og:site_name" content="c4Lab" />

src/test/setup.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
11
import "@testing-library/jest-dom/vitest";
2+
3+
function createInMemoryStorage(): Storage {
4+
const values = new Map<string, string>();
5+
6+
return {
7+
get length() {
8+
return values.size;
9+
},
10+
clear() {
11+
values.clear();
12+
},
13+
getItem(key: string) {
14+
return values.get(key) ?? null;
15+
},
16+
key(index: number) {
17+
return Array.from(values.keys())[index] ?? null;
18+
},
19+
removeItem(key: string) {
20+
values.delete(key);
21+
},
22+
setItem(key: string, value: string) {
23+
values.set(String(key), String(value));
24+
}
25+
};
26+
}
27+
28+
function hasStorageApi(value: unknown): value is Storage {
29+
return (
30+
typeof value === "object" &&
31+
value !== null &&
32+
typeof (value as Storage).getItem === "function" &&
33+
typeof (value as Storage).setItem === "function" &&
34+
typeof (value as Storage).removeItem === "function" &&
35+
typeof (value as Storage).clear === "function" &&
36+
typeof (value as Storage).key === "function"
37+
);
38+
}
39+
40+
function ensureLocalStorageApi() {
41+
if (typeof window === "undefined") {
42+
return;
43+
}
44+
45+
if (hasStorageApi(window.localStorage)) {
46+
return;
47+
}
48+
49+
Object.defineProperty(window, "localStorage", {
50+
configurable: true,
51+
value: createInMemoryStorage()
52+
});
53+
}
54+
55+
ensureLocalStorageApi();

0 commit comments

Comments
 (0)