Skip to content

Commit 5131bba

Browse files
committed
test(TTY): Force TTY on so it works on CI
1 parent ae6207d commit 5131bba

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

index.test.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ test('logging', () => {
1212
const TAG = 'tests:logging'
1313
const log = getLogger(TAG)
1414

15-
// Will collect logs in this array
1615
let events: LogData[] = []
1716
addHandler(data => events.push(data))
1817

19-
const consoleError = jest.spyOn(console, 'error')
20-
2118
log.debug('a debug message')
22-
expect(consoleError).toHaveBeenCalledWith(
23-
expect.stringMatching(/DEBUG(.*)?a debug message/)
24-
)
2519
expect(events.length).toBe(1)
2620
expect(events[0].tag).toBe(TAG)
2721
expect(events[0].level).toBe(LogLevel.debug)
@@ -34,9 +28,6 @@ test('logging', () => {
3428
message: 'an info message',
3529
stack: 'Just a made up trace'
3630
})
37-
expect(consoleError).toHaveBeenCalledWith(
38-
expect.stringMatching(/INFO(.*)?an info message/)
39-
)
4031
expect(events.length).toBe(2)
4132
expect(events[1].tag).toBe(TAG)
4233
expect(events[1].level).toBe(LogLevel.info)
@@ -50,6 +41,20 @@ test('logging', () => {
5041
expect(events[3].level).toBe(LogLevel.error)
5142
})
5243

44+
test('TTY', () => {
45+
const log = getLogger('tests:tty')
46+
47+
// Fake that we are using a TTY device
48+
process.stderr.isTTY = true
49+
const consoleError = jest.spyOn(console, 'error')
50+
51+
log.error('an error message')
52+
53+
expect(consoleError).toHaveBeenCalledWith(
54+
expect.stringMatching(/ERROR(.*)?an error message/)
55+
)
56+
})
57+
5358
test('non-TTY', () => {
5459
const log = getLogger('tests:non-tty')
5560

0 commit comments

Comments
 (0)