-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-utils.ts
More file actions
52 lines (45 loc) · 1.09 KB
/
test-utils.ts
File metadata and controls
52 lines (45 loc) · 1.09 KB
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
// tslint:disable-next-line
import * as sinon from 'sinon'
import * as nxLogger from './lib/types'
export interface CaptureFn {
(message: any): void
called: number
}
export interface LastEntry {
config: nxLogger.Config
messages: nxLogger.Message[]
verbosity: number
}
export interface DebugFn {
title?: string
last: LastEntry
called: number
}
export const debugTransport = (title?: string): nxLogger.TransportFn & DebugFn => {
const transport: any = (config: nxLogger.Config, messages: nxLogger.Message[], verbosity: number) => {
transport.last = { config, messages, verbosity }
transport.called++
}
transport.title = title
transport.last = { config: null, messages: [] }
transport.called = 0
transport.verbosity = -1
return transport
}
export const capture = (callback: (onLog: CaptureFn) => void) => {
const log = sinon.stub(console, 'log')
let err
const setFake: any = (fn: any) => {
setFake.called++
log.callsFake(fn)
}
setFake.called = 0
try {
callback(setFake)
} catch (e) {
err = e
}
log.restore()
if (err)
throw err
}