Skip to content

Commit 0a65f0a

Browse files
authored
Fix an error with meow in cli.js (#152)
1 parent 187e0f0 commit 0a65f0a

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cache/
22
reports/
3+
.DS_Store
34

45
# Created by https://www.toptal.com/developers/gitignore/api/node
56
# Edit at https://www.toptal.com/developers/gitignore?templates=node

cli.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ const cli = meow(createHelpText(), {
194194
allowUnknownFlags: false,
195195
importMeta: import.meta,
196196
inferType: false,
197-
input: [],
198197
flags: CLI_FLAGS,
199198
})
200199

test/cli.test.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
import {spawnSync} from 'node:child_process'
2+
import {readFileSync} from 'node:fs'
3+
import {fileURLToPath} from 'node:url'
4+
5+
const cliPath = fileURLToPath(new URL('../cli.js', import.meta.url))
6+
const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
7+
8+
/**
9+
* Run the CLI in a child process so the entrypoint is exercised end to end.
10+
* @param {string[]} args - CLI arguments
11+
* @returns {import('node:child_process').SpawnSyncReturns<string>} Child process result
12+
*/
13+
function runCli(args) {
14+
return spawnSync(process.execPath, [cliPath, ...args], {
15+
encoding: 'utf8',
16+
env: {
17+
...process.env,
18+
DEBUG: 'false',
19+
GITHUB_TOKEN: '',
20+
},
21+
})
22+
}
23+
124
describe('cli', () => {
225
beforeEach(() => {})
326

@@ -7,13 +30,22 @@ describe('cli', () => {
730
* Test CLI help functionality
831
*/
932
test('should display help information with --help flag', () => {
10-
// TODO: Implement test logic
33+
const result = runCli(['--help'])
34+
35+
expect(result.status).toBe(0)
36+
expect(result.stdout).toContain('Usage')
37+
expect(result.stdout).toContain('action-reporting-cli')
1138
})
1239

1340
/**
1441
* Test CLI version functionality
1542
*/
1643
test('should display version information with --version flag', () => {
17-
// TODO: Implement test logic
44+
const result = runCli(['--version'])
45+
const outputLines = result.stdout.trim().split('\n')
46+
const lastLine = outputLines[outputLines.length - 1]
47+
48+
expect(result.status).toBe(0)
49+
expect(lastLine).toBe(packageJson.version)
1850
})
1951
})

0 commit comments

Comments
 (0)