Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cache/
reports/
.DS_Store

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
Expand Down
1 change: 0 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ const cli = meow(createHelpText(), {
allowUnknownFlags: false,
importMeta: import.meta,
inferType: false,
input: [],
flags: CLI_FLAGS,
})

Expand Down
36 changes: 34 additions & 2 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
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(() => {})

Expand All @@ -7,13 +30,22 @@ describe('cli', () => {
* Test CLI help functionality
*/
test('should display help information with --help flag', () => {
// TODO: Implement test logic
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', () => {
// TODO: Implement test logic
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)
})
})
Loading