mirror of
https://github.com/bs-community/blessing-skin-plugins.git
synced 2025-01-09 04:07:51 +08:00
setup Jest
This commit is contained in:
parent
259ede7994
commit
a70366b302
6
jest.config.json
Normal file
6
jest.config.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"preset": "ts-jest",
|
||||
"moduleNameMapper": {
|
||||
"blessing-skin": "<rootDir>/types.ts"
|
||||
}
|
||||
}
|
@ -16,16 +16,19 @@
|
||||
"@rollup/plugin-commonjs": "^15.0.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@rollup/plugin-typescript": "^5.0.2",
|
||||
"@types/node": "^14.0.13",
|
||||
"@types/jest": "^26.0.10",
|
||||
"@types/node": "^14.6.1",
|
||||
"@types/react": "^16.9.32",
|
||||
"@types/react-dom": "^16.9.6",
|
||||
"fast-glob": "^3.2.4",
|
||||
"jest": "^26.4.2",
|
||||
"rollup": "^2.26.5",
|
||||
"rollup-plugin-svelte": "^6.0.0",
|
||||
"rollup-plugin-terser": "^7.0.0",
|
||||
"svelte": "^3.24.1",
|
||||
"svelte-check": "^1.0.26",
|
||||
"svelte-preprocess": "^4.1.1",
|
||||
"ts-jest": "^26.3.0",
|
||||
"tslib": "^2.0.1",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
|
@ -9,7 +9,7 @@
|
||||
"paths": {
|
||||
"blessing-skin": ["./types"]
|
||||
},
|
||||
"types": ["svelte"]
|
||||
"types": ["svelte", "jest", "node"]
|
||||
},
|
||||
"include": [
|
||||
"plugins/*/assets",
|
||||
|
86
types.ts
86
types.ts
@ -1,33 +1,77 @@
|
||||
declare class Toast {
|
||||
success(message: string): void
|
||||
info(message: string): void
|
||||
warning(message: string): void
|
||||
error(message: string): void
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
export let base_url: string
|
||||
export let locale: string
|
||||
export let site_name: string
|
||||
export let base_url = '/'
|
||||
export let locale = 'en'
|
||||
export let site_name = 'Blessing Skin'
|
||||
export let version: string
|
||||
export let route: string
|
||||
|
||||
export let t: (key: string, params?: object) => string
|
||||
|
||||
export let fetch: {
|
||||
get<T = any>(url: string, params?: object): Promise<T>
|
||||
post<T = any>(url: string, data?: object): Promise<T>
|
||||
put<T = any>(url: string, data?: object): Promise<T>
|
||||
del<T = any>(url: string, data?: object): Promise<T>
|
||||
export function t(key: string, params?: object) {
|
||||
return `${key}(${JSON.stringify(params)})`
|
||||
}
|
||||
|
||||
export let event: {
|
||||
on(eventName: string | symbol, listener: Function): void
|
||||
emit(eventName: string | symbol, payload: object): void
|
||||
export const fetch = {
|
||||
async get<T = any>(url: string, params?: Record<string, string>): Promise<T> {
|
||||
url
|
||||
params
|
||||
return {} as T
|
||||
},
|
||||
async post<T = any>(
|
||||
url: string,
|
||||
data?: Record<string, string> | FormData,
|
||||
): Promise<T> {
|
||||
url
|
||||
data
|
||||
return {} as T
|
||||
},
|
||||
async put<T = any>(
|
||||
url: string,
|
||||
data?: Record<string, string> | FormData,
|
||||
): Promise<T> {
|
||||
url
|
||||
data
|
||||
return {} as T
|
||||
},
|
||||
async del<T = any>(
|
||||
url: string,
|
||||
data?: Record<string, string> | FormData,
|
||||
): Promise<T> {
|
||||
url
|
||||
data
|
||||
return {} as T
|
||||
},
|
||||
}
|
||||
|
||||
export let notify: {
|
||||
showModal(options?: object): Promise<{ value: string }>
|
||||
toast: Toast
|
||||
const emitter = new EventEmitter()
|
||||
export const event = {
|
||||
on(eventName: string | symbol, listener: (...args: any[]) => any): void {
|
||||
emitter.on(eventName, listener)
|
||||
},
|
||||
emit(eventName: string | symbol, payload?: object): void {
|
||||
emitter.emit(eventName, payload)
|
||||
},
|
||||
}
|
||||
|
||||
export const notify = {
|
||||
showModal(options?: object): Promise<{ value: string }> {
|
||||
return Promise.resolve({ value: JSON.stringify(options) })
|
||||
},
|
||||
toast: new Toast(),
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
Loading…
Reference in New Issue
Block a user