Skip to content
Closed
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
32 changes: 31 additions & 1 deletion web/scripts/__tests__/check-bot-write-access.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import {
findInstallation,
formatTextResult,
Expand Down Expand Up @@ -26,6 +26,36 @@ describe('parseArgs', () => {
json: true,
});
});

it('prints help and exits 0 for --help', () => {
const log = vi.spyOn(console, 'log').mockImplementation(() => {});
const exit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});

try {
expect(() => parseArgs(['--help'])).toThrow('process.exit');
expect(log).toHaveBeenCalledWith(
expect.stringContaining('Usage: npm run check-bot-write-access')
);
expect(exit).toHaveBeenCalledWith(0);
} finally {
log.mockRestore();
exit.mockRestore();
}
});

it('rejects unknown flags', () => {
expect(() => parseArgs(['--verbose'])).toThrow(
'Unknown argument: --verbose'
);
});

it('rejects positional arguments', () => {
expect(() => parseArgs(['example-org'])).toThrow(
'Unknown argument: example-org'
);
});
});

describe('findInstallation', () => {
Expand Down
10 changes: 9 additions & 1 deletion web/scripts/check-bot-write-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function parseArgs(argv: string[]): CliOptions {
printHelp();
process.exit(0);
}

throw new Error(`Unknown argument: ${arg}`);
}

return options;
Expand Down Expand Up @@ -249,5 +251,11 @@ const isMainModule =
process.argv[1] === fileURLToPath(import.meta.url);

if (isMainModule) {
main();
try {
main();
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.error(message);
process.exit(1);
}
}
Loading