forked from mcollina/borp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-help.test.js
More file actions
94 lines (80 loc) · 3.77 KB
/
cli-help.test.js
File metadata and controls
94 lines (80 loc) · 3.77 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
86
87
88
89
90
91
92
93
94
import { test } from 'node:test'
import { execa } from 'execa'
import { join } from 'desm'
import { rejects, strictEqual } from 'node:assert'
const borp = join(import.meta.url, '..', 'borp.js')
const isWindows = process.platform === 'win32'
delete process.env.GITHUB_ACTION
test('invalid option shows help text', { skip: isWindows }, async () => {
const testCwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
await rejects(async () => {
await execa('node', [borp, '--invalid-option'], {
cwd: testCwd,
timeout: 15000
})
throw new Error('Expected command to fail')
}, (error) => {
strictEqual(error.exitCode, 1)
strictEqual(error.stderr.includes('Error: Unknown option \'--invalid-option\''), true, 'Should show error message')
strictEqual(error.stderr.includes('Usage: borp [options] [files...]'), true, 'Should show usage line')
strictEqual(error.stderr.includes('--help'), true, 'Should show help option')
strictEqual(error.stderr.includes('--coverage'), true, 'Should show coverage option')
strictEqual(error.stderr.includes('--coverage-html'), true, 'Should show html option')
strictEqual(error.stderr.includes('Examples:'), true, 'Should show examples section')
return true
})
})
test('multiple invalid options show help text', { skip: isWindows }, async () => {
const testCwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
await rejects(async () => {
await execa('node', [borp, '--foo', '--bar'], {
cwd: testCwd,
timeout: 15000
})
throw new Error('Expected command to fail')
}, (error) => {
strictEqual(error.exitCode, 1)
strictEqual(error.stderr.includes('Error: Unknown option \'--foo\''), true, 'Should show error for first invalid option')
strictEqual(error.stderr.includes('Usage: borp [options] [files...]'), true, 'Should show help text')
return true
})
})
test('invalid short option shows help text', { skip: isWindows }, async () => {
const testCwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
await rejects(async () => {
await execa('node', [borp, '-z'], {
cwd: testCwd,
timeout: 15000
})
throw new Error('Expected command to fail')
}, (error) => {
strictEqual(error.exitCode, 1)
strictEqual(error.stderr.includes('Error: Unknown option \'-z\''), true, 'Should show error message')
strictEqual(error.stderr.includes('Usage: borp [options] [files...]'), true, 'Should show help text')
return true
})
})
test('--help option shows help text and exits successfully', { skip: isWindows }, async () => {
const testCwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
const { stdout, exitCode } = await execa('node', [borp, '--help'], {
cwd: testCwd,
timeout: 15000
})
strictEqual(exitCode, 0, 'Should exit with code 0')
strictEqual(stdout.includes('Usage: borp [options] [files...]'), true, 'Should show usage line')
strictEqual(stdout.includes('--help'), true, 'Should show help option')
strictEqual(stdout.includes('--coverage'), true, 'Should show coverage option')
strictEqual(stdout.includes('--coverage-html'), true, 'Should show html option')
strictEqual(stdout.includes('Examples:'), true, 'Should show examples section')
strictEqual(stdout.includes('borp --coverage'), true, 'Should show coverage example')
})
test('-h option shows help text and exits successfully', { skip: isWindows }, async () => {
const testCwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
const { stdout, exitCode } = await execa('node', [borp, '-h'], {
cwd: testCwd,
timeout: 15000
})
strictEqual(exitCode, 0, 'Should exit with code 0')
strictEqual(stdout.includes('Usage: borp [options] [files...]'), true, 'Should show usage line')
strictEqual(stdout.includes('Examples:'), true, 'Should show examples section')
})