-
Notifications
You must be signed in to change notification settings - Fork 53
/
tests.js
44 lines (32 loc) · 1.21 KB
/
tests.js
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
import { promises as fs } from 'fs'
import test from 'ava'
import tmp from 'tmp-promise'
import { getSystemLogger } from '../../../src/log/logger.js'
import { normalizeOutput } from '../../helpers/normalize.js'
test('System logger writes to file descriptor', async (t) => {
const { fd, cleanup, path } = await tmp.file()
const mockProcess = {
stdout: [],
}
const systemLog = getSystemLogger(mockProcess, false, fd)
const error = new Error('Something went wrong')
systemLog('Hello world', { object: true, problem: false }, error)
const output = normalizeOutput(await fs.readFile(path, 'utf8'))
t.snapshot(output)
t.is(mockProcess.stdout.length, 0)
await cleanup()
})
test('System logger does not write to file descriptor when `debug: true`', async (t) => {
const { fd, cleanup, path } = await tmp.file()
const mockProcess = {
stdout: [],
}
const systemLog = getSystemLogger(mockProcess, true, fd)
const error = new Error('Something went wrong')
systemLog('Hello world', { object: true, problem: false }, error)
const output = normalizeOutput(mockProcess.stdout[0])
t.is(mockProcess.stdout.length, 1)
t.snapshot(output)
t.is(await fs.readFile(path, 'utf8'), '')
await cleanup()
})