Skip to content

Commit 42c46ff

Browse files
committed
feat: unit test watch
1 parent c100555 commit 42c46ff

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

index.d.ts

+34-25
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface port {
9898
now: () => hrtime
9999
},
100100
fireEvent(event: string, data: any, mapper?: 'asyncMap' | 'reduce'),
101+
config: Record<string, unknown>,
101102
[name: string]: any
102103
}
103104

@@ -114,6 +115,29 @@ interface vfs {
114115
readFileSync: typeof readFileSync;
115116
}
116117

118+
type info = () => {
119+
encrypt: object,
120+
sign: object,
121+
uri: string,
122+
port: number | string,
123+
host: string,
124+
address: undefined | string,
125+
protocol: 'http' | 'https' | 'socket'
126+
}
127+
128+
interface serviceBus {
129+
config: Record<string, unknown>,
130+
jsonrpc: object,
131+
rpc: {
132+
info: info
133+
},
134+
publicApi: {
135+
config: Record<string, unknown>,
136+
importMethod: (name: string) => (params, $meta) => any
137+
info: info
138+
}
139+
}
140+
117141
type api<imports> = {
118142
joi: joi.Root,
119143
/**
@@ -166,20 +190,7 @@ type api<imports> = {
166190
version: (version: string) => boolean,
167191
vfs: vfs,
168192
callSite: () => CallSiteLike,
169-
utBus: {
170-
config: {
171-
workDir: string
172-
},
173-
info: () => {
174-
encrypt: object,
175-
sign: object,
176-
uri: string,
177-
port: number | string,
178-
host: string,
179-
address: undefined | string,
180-
protocol: 'http' | 'https' | 'socket'
181-
}
182-
}
193+
utBus: serviceBus['publicApi']
183194
}
184195

185196
interface genericExport {
@@ -345,13 +356,9 @@ export function run(params: {
345356
root?: string,
346357
resolve?: (string) => string
347358
}): Promise<{
348-
ports: {}[],
349-
portsMap: Record<string, any>,
350-
serviceBus: {
351-
publicApi: {
352-
importMethod: (name: string) => (params, $meta) => any
353-
}
354-
},
359+
ports: port[],
360+
portsMap: Record<string, port>,
361+
serviceBus: serviceBus,
355362
log: any,
356363
logger: any,
357364
config: {},
@@ -368,8 +375,10 @@ export function microservice(module: Partial<NodeJS.Module>, require: NodeJS.Req
368375

369376
type Step<methods> = {
370377
name: string,
371-
params?: () => boolean,
378+
params?: any,
372379
steps?: () => (Step<methods> | string)[]
380+
result?: (this: any, result: any, assert: Tap.Test, $meta?: meta) => void,
381+
error?: (this: any, error: any, assert: Tap.Test, $meta?: meta) => void
373382
} | {
374383
[Property in keyof methods]: methods[Property] extends ((...args: any) => any) ? {
375384
method: Property,
@@ -407,13 +416,13 @@ type Imported<methods> = {
407416

408417
export type test<methods> = () => Record<string, (
409418
test: unknown,
410-
bus: unknown,
419+
bus: serviceBus,
411420
run: (
412421
test: unknown,
413-
bus: unknown,
422+
bus: serviceBus,
414423
steps: (Step<methods> | string)[]
415424
) => unknown,
416-
ports: {}[],
425+
ports: port[],
417426
steps: Record<string, Imported<methods>>
418427
) => unknown>;
419428

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"stack-utils": "2.0.5",
1919
"through2": "2.0.3",
2020
"ut-bus": "^7.62.18",
21-
"ut-config": "^7.9.3",
21+
"ut-config": "^7.10.0",
2222
"ut-function.merge": "^1.5.6",
2323
"ut-log": "^6.10.5",
2424
"ut-port": "^6.44.1",

unit.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ module.exports = function unit(serviceConfig, {params, ...envConfig}, assert, vf
1212
implementation: 'test',
1313
repl: false,
1414
run: {
15-
logLevel: 'warn'
15+
logLevel: 'warn',
16+
...params.watch && {
17+
hotReload: true,
18+
logLevel: 'trace',
19+
test: {
20+
prompt: 1
21+
}
22+
}
1623
},
1724
db: {
1825
debug: true

0 commit comments

Comments
 (0)