setup Jest

This commit is contained in:
Pig Fang 2020-08-28 09:32:15 +08:00
parent 259ede7994
commit a70366b302
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
5 changed files with 3377 additions and 39 deletions

6
jest.config.json Normal file
View File

@ -0,0 +1,6 @@
{
"preset": "ts-jest",
"moduleNameMapper": {
"blessing-skin": "<rootDir>/types.ts"
}
}

View File

@ -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"
},

View File

@ -9,7 +9,7 @@
"paths": {
"blessing-skin": ["./types"]
},
"types": ["svelte"]
"types": ["svelte", "jest", "node"]
},
"include": [
"plugins/*/assets",

View File

@ -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 {

3317
yarn.lock

File diff suppressed because it is too large Load Diff