This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
examples.test.js
97 lines (83 loc) · 1.8 KB
/
examples.test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const childProcess = require('child_process')
const path = require('path')
const { promisify } = require('util')
const test = require('ava')
const exec = promisify(childProcess.exec)
const examplesDir = path.join(__dirname, 'examples')
const examples = [
{ name: 'simple', out: 'hello world\n', err: '' },
{ name: 'console-log', out: 'hello world\n', err: '' },
{
name: 'component',
out:
`app starting
[counter] starting
[counter] started
app ready
[counter|event] counting | count: 1
[counter|event] counting | count: 2
[counter] stopped
app shutting down
`,
err: ''
},
{
name: 'component-with-metrics',
out:
`app starting
[counter] starting
[counter] started
app ready
[counter|event] counting | count: 1
[counter|event] counting | count: 2
[counter] stopped
app shutting down
`,
err:
`count = 1
count = 3
`
},
{ name: 'debug', out: 'log\n', err: '' },
{
name: 'debug-only',
out: 'log\n[debug] debugging only\n',
err: '',
env: { DEBUG: true }
},
{
name: 'json-output',
out:
`{"message":"log","tags":[],"fields":{}}
{"message":"debugging only","tags":["debug"],"fields":{}}
`,
err: ''
}
]
examples.forEach(example => {
test(example.name, async t => {
const examplePath = path.join(examplesDir, example.name + '.js')
const options = { env: { ...process.env, ...example.env } }
const {stdout, stderr} = await exec('node ' + examplePath, options)
t.is(stdout, example.out)
t.is(stderr, example.err)
}
)
})
test('TypeScript typings', async t => {
const out =
`msg
msg | count: 2 | path: /
[a|b] msg
[tag] msg
[tag] msg
[a|b] msg
[tag] msg
[scope] msg
`
const examplePath = path.join(examplesDir, 'typings.ts')
const {stdout, stderr} = await exec('ts-node --typeCheck ' + examplePath)
t.is(stdout, out)
t.is(stderr, '')
}
)