-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.test.mjs
80 lines (64 loc) · 1.88 KB
/
cli.test.mjs
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
import { test } from 'tap'
import { spawn } from 'child_process'
const bin = './cli.mjs'
process.env.DEBUG = '*'
test('run server with default port', (t) => {
const timeout = 5000
t.plan(1)
t.setTimeout(timeout)
const child = spawn(bin, ['server', './example/api.mjs'])
child.on('error', (err) => t.fail(err))
child.stderr.on('data', (data) => {
if (data.toString().includes('Listening on port ')) {
t.pass('Server is listening')
}
})
setTimeout(() => {
child.kill('SIGINT')
t.end()
}, timeout - 500)
})
test('run server with custom port', (t) => {
const child = spawn(bin, ['server', '--port', '4000', './example/api.mjs'])
child.on('error', (err) => t.fail(err))
child.stderr.on('data', (data) => {
if (data.toString().includes('Listening on port 4000')) {
t.pass()
t.end()
}
})
setTimeout(() => {
child.kill('SIGINT')
}, 500)
})
test('output schema', (t) => {
const child = spawn(bin, ['schema', './example/api.mjs'])
child.on('error', (err) => t.fail(err))
child.stdout.on('data', (data) => {
t.doesNotThrow(() => JSON.parse(data), 'Output is valid JSON')
t.end()
})
})
test('run REPL', (t) => {
t.plan(1)
const child = spawn(bin, ['repl', './example/api.mjs', '--verbose'])
child.on('error', (err) => t.fail(err))
child.stderr.on('data', (data) => {
if (data.toString().includes('furver:repl Starting REPL')) {
t.pass('REPL started')
}
})
setTimeout(() => {
child.kill('SIGINT')
}, 500)
})
// test.skip('execute command with API endpoint', (t) => {
// const child = spawn(bin, ['--exec', '["identity", 42]', '--endpoint', 'http://localhost:3000'])
//
// child.on('error', (err) => t.fail(err))
// child.stderr.on('data', (data) => t.fail(data))
// child.stdout.on('data', (data) => {
// t.ok(data.toString().includes('3'), 'Command executed')
// t.end()
// })
// })