|
| 1 | +import path from 'node:path' |
| 2 | + |
| 3 | +import { describe, expect } from 'vitest' |
| 4 | + |
| 5 | +import constants from '../../../dist/constants.js' |
| 6 | +import { cmdit, invokeNpm } from '../../../test/utils' |
| 7 | + |
| 8 | +const { CLI } = constants |
| 9 | + |
| 10 | +describe('socket oops', async () => { |
| 11 | + // Lazily access constants.rootBinPath. |
| 12 | + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) |
| 13 | + |
| 14 | + cmdit( |
| 15 | + ['oops', '--help', '--config', '{}'], |
| 16 | + 'should support --help', |
| 17 | + async cmd => { |
| 18 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 19 | + expect(stdout).toMatchInlineSnapshot( |
| 20 | + ` |
| 21 | + "Trigger an intentional error (for development) |
| 22 | +
|
| 23 | + Usage |
| 24 | + $ socket oops oops |
| 25 | +
|
| 26 | + Don't run me." |
| 27 | + ` |
| 28 | + ) |
| 29 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 30 | + " |
| 31 | + _____ _ _ /--------------- |
| 32 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 33 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 34 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket oops\`, cwd: <redacted>" |
| 35 | + `) |
| 36 | + |
| 37 | + expect(code, 'help should exit with code 2').toBe(2) |
| 38 | + expect(stderr, 'banner includes base command').toContain('`socket oops`') |
| 39 | + } |
| 40 | + ) |
| 41 | + |
| 42 | + cmdit( |
| 43 | + ['oops', '--dry-run', '--config', '{"apiToken":"anything"}'], |
| 44 | + 'should require args with just dry-run', |
| 45 | + async cmd => { |
| 46 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 47 | + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) |
| 48 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 49 | + " |
| 50 | + _____ _ _ /--------------- |
| 51 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 52 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 53 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket oops\`, cwd: <redacted>" |
| 54 | + `) |
| 55 | + |
| 56 | + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) |
| 57 | + } |
| 58 | + ) |
| 59 | +}) |
0 commit comments