-
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathtest.tsx
More file actions
77 lines (65 loc) · 2.78 KB
/
test.tsx
File metadata and controls
77 lines (65 loc) · 2.78 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
import childProcess from 'node:child_process';
import {execa} from 'execa';
import {pEvent} from 'p-event';
import test from 'ava';
test('default', async t => {
const subprocess = childProcess.spawn('node', ['./distribution/cli.js'], {stdio: 'inherit'});
t.is(await pEvent(subprocess, 'close'), 0);
});
test('non-tty output', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js'], {timeout: 60_000});
t.regex(stdout, /^\d+(?:\.\d+)? [MGKB]bps$/);
});
test('json output', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--json'], {timeout: 60_000});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const data = JSON.parse(stdout);
t.truthy(data.downloadSpeed);
t.truthy(data.downloadUnit);
t.is(typeof data.downloadSpeed, 'number');
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
t.regex(data.downloadUnit, /^[MGKB]bps$/);
t.true(Array.isArray(data.serverLocations));
});
test('upload flag', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--upload'], {timeout: 90_000});
// Filter out lines that are only escape sequences or empty
const lines = stdout.split('\n').filter(line => /\d+(?:\.\d+)?\s+[MGKB]bps/.test(line));
t.is(lines.length, 2, 'Should output download and upload speeds');
t.regex(lines[0], /^\d+(?:\.\d+)?\s+[MGKB]bps$/);
t.regex(lines[1], /^\d+(?:\.\d+)?\s+[MGKB]bps$/);
});
test('help output', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--help']);
t.true(stdout.includes('Test your download and upload speed'));
t.true(stdout.includes('--upload'));
t.true(stdout.includes('--json'));
});
test('json upload output', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--upload', '--json'], {timeout: 90_000});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const data = JSON.parse(stdout);
t.truthy(data.downloadSpeed);
t.truthy(data.uploadSpeed);
t.is(data.downloadUnit, 'Mbps');
t.is(data.uploadUnit, 'Mbps');
t.is(typeof data.downloadSpeed, 'number');
t.is(typeof data.uploadSpeed, 'number');
});
test('verbose flag', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--verbose'], {timeout: 90_000});
// Should contain speed measurement
t.regex(stdout, /\d+(?:\.\d+)?\s+[MGKB]bps/);
// Should contain latency information
t.regex(stdout, /Latency:/);
t.regex(stdout, /\d+\s+ms/);
// Should contain client information
t.regex(stdout, /Client:/);
// Should contain server information
t.regex(stdout, /Server:/);
});
test('verbose flag in help', async t => {
const {stdout} = await execa('node', ['./distribution/cli.js', '--help']);
t.true(stdout.includes('--verbose'));
t.true(stdout.includes('Include latency and server location information'));
});