-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-test.ts
85 lines (76 loc) · 1.53 KB
/
setup-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { EventEmitter } from 'events'
class Toast {
success(message: string): void {
message
}
info(message: string): void {
message
}
warning(message: string): void {
message
}
error(message: string): void {
message
}
}
const base_url = '/'
const locale = 'en'
const site_name = 'Blessing Skin'
function t(key: string, params?: object): string {
const data = params ? `(${JSON.stringify(params)})` : ''
return key + data
}
const fetch = {
async get<T = any>(url: string, params?: Record<string, any>): Promise<T> {
url
params
return {} as T
},
async post<T = any>(url: string, data?: any): Promise<T> {
url
data
return {} as T
},
async put<T = any>(url: string, data?: any): Promise<T> {
url
data
return {} as T
},
async del<T = any>(url: string, data?: any): Promise<T> {
url
data
return {} as T
},
}
const emitter = new EventEmitter()
const event = {
on(
eventName: string | symbol,
listener: (...args: any[]) => any,
): () => void {
emitter.on(eventName, listener)
return () => {
emitter.off(eventName, listener)
}
},
emit(eventName: string | symbol, payload?: object): void {
emitter.emit(eventName, payload)
},
}
const notify = {
showModal(options?: object): Promise<{ value: string }> {
return Promise.resolve({ value: JSON.stringify(options) })
},
toast: new Toast(),
}
Object.assign(globalThis, {
blessing: {
base_url,
locale,
site_name,
t,
fetch,
event,
notify,
},
})