-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathcapture_spec.ts
More file actions
65 lines (50 loc) · 1.47 KB
/
capture_spec.ts
File metadata and controls
65 lines (50 loc) · 1.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable no-console */
import * as capture from '../../lib/capture'
describe('lib/capture', () => {
afterEach(() => {
return capture.restore()
})
context('process.stdout.write', () => {
beforeEach(function () {
this.write = sinon.spy(process.stdout, 'write')
this.captured = capture.stdout()
})
it('slurps up stdout', function () {
console.log('foo')
console.log('bar')
process.stdout.write('baz')
expect(this.captured.data).to.deep.eq([
'foo\n',
'bar\n',
'baz',
])
expect(this.captured.toString()).to.eq('foo\nbar\nbaz')
// should still call through to write
expect(this.write).to.be.calledWith('foo\n')
expect(this.write).to.be.calledWith('bar\n')
expect(this.write).to.be.calledWith('baz')
})
})
context('process.log', () => {
beforeEach(function () {
this.log = process.log
this.logStub = (process.log = sinon.stub())
this.captured = capture.stdout()
})
afterEach(function () {
process.log = this.log
})
it('slurps up logs', function () {
process.log('foo\n')
process.log('bar\n')
expect(this.captured.data).to.deep.eq([
'foo\n',
'bar\n',
])
expect(this.captured.toString()).to.eq('foo\nbar\n')
// should still call through to write
expect(this.logStub).to.be.calledWith('foo\n')
expect(this.logStub).to.be.calledWith('bar\n')
})
})
})