This repository was archived by the owner on Aug 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.test.js
More file actions
51 lines (43 loc) · 1.4 KB
/
Copy pathcli.test.js
File metadata and controls
51 lines (43 loc) · 1.4 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
import {spawnSync} from 'node:child_process'
import {readFileSync} from 'node:fs'
import {fileURLToPath} from 'node:url'
const cliPath = fileURLToPath(new URL('../cli.js', import.meta.url))
const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
/**
* Run the CLI in a child process so the entrypoint is exercised end to end.
* @param {string[]} args - CLI arguments
* @returns {import('node:child_process').SpawnSyncReturns<string>} Child process result
*/
function runCli(args) {
return spawnSync(process.execPath, [cliPath, ...args], {
encoding: 'utf8',
env: {
...process.env,
DEBUG: 'false',
GITHUB_TOKEN: '',
},
})
}
describe('cli', () => {
beforeEach(() => {})
afterEach(() => {})
/**
* Test CLI help functionality
*/
test('should display help information with --help flag', () => {
const result = runCli(['--help'])
expect(result.status).toBe(0)
expect(result.stdout).toContain('Usage')
expect(result.stdout).toContain('action-reporting-cli')
})
/**
* Test CLI version functionality
*/
test('should display version information with --version flag', () => {
const result = runCli(['--version'])
const outputLines = result.stdout.trim().split('\n')
const lastLine = outputLines[outputLines.length - 1]
expect(result.status).toBe(0)
expect(lastLine).toBe(packageJson.version)
})
})