This repository was archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.js
More file actions
85 lines (81 loc) · 2.2 KB
/
run.js
File metadata and controls
85 lines (81 loc) · 2.2 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { TestServer } from '@logux/server'
import { createSpinner } from 'nanospinner'
import pico from 'picocolors'
import { local } from './local.js'
import { tests } from './tests/index.js'
async function runTest(data) {
let prefix = pico.gray((data.index + ' ').padStart(3, ' '))
let spinner = createSpinner(prefix + tests[data.index].title).start()
let server = new TestServer({
auth: false,
backend: data.backend === 'local' ? undefined : data.backend,
controlSecret: data.controlSecret,
supports: data.backend === 'local' ? '^1.0.0' : undefined
})
if (data.backend === 'local') {
local(server)
}
await server.listen()
try {
await tests[data.index].test({ ...data, server })
spinner.success()
} catch (e) {
spinner.error()
process.stderr.write('\n')
if (e.assert) {
let files = e.stack.split('\n').map(i => {
let match = i.match(/\((.*)\)$/)
return match ? match[1] : ''
})
let file = files.find(i => {
return /[/\\]tests[/\\]\w+\.js/.test(i) && !i.includes('util.js:')
})
process.stderr.write(
' ' +
pico.bold(pico.red(e.message)) +
'\n\nTest: ' +
pico.yellow(file) +
'\nRe-run it: ' +
pico.yellow(
'npx @logux/backend-test ' +
data.backend +
' ' +
pico.bold(data.index)
) +
'\n'
)
process.exit(1)
} else {
process.stderr.write(
'Re-run test: ' +
pico.yellow(
'npx @logux/backend-test ' +
data.backend +
' ' +
pico.bold(data.index)
) +
'\n\n'
)
throw e
}
} finally {
server.destroy()
for (let client of server.connected.values()) {
client.destroy()
}
}
}
export async function run(backend, controlSecret, only, ignore) {
if (only && !tests[only]) {
throw new Error('Unknown test ' + only)
}
if (only) {
await runTest({ backend, controlSecret, index: only })
} else {
for (let i = 0; i < tests.length; i++) {
if (!ignore.includes(i)) {
await runTest({ backend, controlSecret, index: i })
}
}
}
}