|
| 1 | +import { describe, expect } from 'vitest' |
| 2 | + |
| 3 | +import constants from '../../../src/constants.mts' |
| 4 | +import { cmdit, invokeNpm } from '../../../test/utils.mts' |
| 5 | + |
| 6 | +describe('socket scan reach', async () => { |
| 7 | + // Lazily access constants.binCliPath. |
| 8 | + const { binCliPath } = constants |
| 9 | + |
| 10 | + cmdit( |
| 11 | + ['scan', 'reach', '--help', '--config', '{}'], |
| 12 | + 'should support --help', |
| 13 | + async cmd => { |
| 14 | + const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd) |
| 15 | + expect(stdout).toMatchInlineSnapshot( |
| 16 | + ` |
| 17 | + "Compute tier 1 reachability |
| 18 | +
|
| 19 | + Usage |
| 20 | + $ socket scan reach [CWD=.] |
| 21 | +
|
| 22 | + Options |
| 23 | + --help Print this help |
| 24 | + --interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no. |
| 25 | + --json Output result as json |
| 26 | + --markdown Output result as markdown |
| 27 | +
|
| 28 | + Examples |
| 29 | + $ socket scan reach |
| 30 | + $ socket scan reach ./proj" |
| 31 | + `, |
| 32 | + ) |
| 33 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 34 | + " |
| 35 | + _____ _ _ /--------------- |
| 36 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 37 | + |__ | * | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 38 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket scan reach\`, cwd: <redacted>" |
| 39 | + `) |
| 40 | + |
| 41 | + expect(code, 'explicit help should exit with code 0').toBe(0) |
| 42 | + expect(stderr, 'banner includes base command').toContain( |
| 43 | + '`socket scan reach`', |
| 44 | + ) |
| 45 | + }, |
| 46 | + ) |
| 47 | + |
| 48 | + cmdit( |
| 49 | + ['scan', 'reach', '--dry-run', '--config', '{}'], |
| 50 | + 'should require args with just dry-run', |
| 51 | + async cmd => { |
| 52 | + const { code, stderr, stdout } = await invokeNpm(binCliPath, cmd) |
| 53 | + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) |
| 54 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 55 | + " |
| 56 | + _____ _ _ /--------------- |
| 57 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 58 | + |__ | * | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 59 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket scan reach\`, cwd: <redacted> |
| 60 | +
|
| 61 | + \\x1b[34mi\\x1b[39m If you dont have any interactive bits then drop the flag true" |
| 62 | + `) |
| 63 | + |
| 64 | + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) |
| 65 | + }, |
| 66 | + ) |
| 67 | +}) |
0 commit comments