Skip to content

Commit d8b299e

Browse files
committed
test(e2e): port threat-feed + oops sections + CLI top-level checks
Three small focused files instead of a 'misc' catch-all (each one names exactly what it tests): - threat-feed.e2e.test.mts (6 tests): help / dry-run / interactive default / --no-interactive / --json contract / --markdown. - oops.e2e.test.mts (3 tests): deliberate-failure command; no-arg exits 1 by design. - cli-help.e2e.test.mts (2 tests): --version (lenient on the known exit-2 quirk) and --help (must list 'Main commands'). Absorbed from the (next commit's) critical-commands.e2e.test.mts deletion.
1 parent a7c861f commit d8b299e

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @file E2E tests for the Socket CLI's top-level `--help` / `--version`
3+
* behavior. Absorbed from the (now-deleted) critical-commands.e2e.test.mts
4+
* "Basic commands (no auth required)" group.
5+
*
6+
* No auth required.
7+
*/
8+
9+
import { describe, expect, it } from 'vitest'
10+
11+
import { ENV } from '../../src/constants/env.mts'
12+
import { executeCliCommand } from '../helpers/cli-execution.mts'
13+
14+
const RUN = ENV.RUN_E2E_TESTS
15+
16+
describe('socket CLI top-level (e2e)', () => {
17+
it.skipIf(!RUN)('--version produces output (known quirk: may exit 2)', async () => {
18+
// Note: --version currently shows help and exits with code 2 (known
19+
// issue). This test validates the CLI executes without crashing — the
20+
// exact exit code is intentionally lenient so the test doesn't break
21+
// when the quirk is fixed.
22+
const result = await executeCliCommand(['--version'], { isolateConfig: false })
23+
expect(result.code).toBeGreaterThanOrEqual(0)
24+
expect(result.stdout.length).toBeGreaterThan(0)
25+
})
26+
27+
it.skipIf(!RUN)('--help exits 0 and lists main commands', async () => {
28+
const result = await executeCliCommand(['--help'], { isolateConfig: false })
29+
expect(result.code).toBe(0)
30+
expect(result.stdout).toContain('socket')
31+
expect(result.stdout).toContain('Main commands')
32+
})
33+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @file E2E tests for `socket oops`. Ported from
3+
* `packages/cli/test/smoke.sh`'s oops section (4 commands).
4+
*
5+
* `oops` is a deliberate-failure command used in regression tests; the
6+
* no-arg form exits 1 by design.
7+
*
8+
* Gated on `RUN_E2E_TESTS=1`.
9+
*/
10+
11+
import { describe, expect, it } from 'vitest'
12+
13+
import { ENV } from '../../src/constants/env.mts'
14+
import { executeCliCommand } from '../helpers/cli-execution.mts'
15+
16+
const RUN = ENV.RUN_E2E_TESTS
17+
18+
describe('socket oops (e2e)', () => {
19+
it.skipIf(!RUN)('oops (no args) exits 1 by design', async () => {
20+
const result = await executeCliCommand(['oops'])
21+
expect(result.code).toBe(1)
22+
})
23+
24+
it.skipIf(!RUN)('oops --help exits 0', async () => {
25+
const result = await executeCliCommand(['oops', '--help'])
26+
expect(result.code).toBe(0)
27+
})
28+
29+
it.skipIf(!RUN)('oops --dry-run exits 0', async () => {
30+
const result = await executeCliCommand(['oops', '--dry-run'])
31+
expect(result.code).toBe(0)
32+
})
33+
})
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file E2E tests for `socket threat-feed`. Ported from
3+
* `packages/cli/test/smoke.sh`'s threat-feed section (6 commands).
4+
*
5+
* threat-feed is interactive by default; smoke.sh notes a "potential
6+
* caching issue" on the first run. The non-interactive forms drive the
7+
* tests here.
8+
*
9+
* Gated on `RUN_E2E_TESTS=1`. Auth required.
10+
*/
11+
12+
import { describe, expect, it } from 'vitest'
13+
14+
import { ENV } from '../../src/constants/env.mts'
15+
import {
16+
executeCliCommand,
17+
validateSocketJsonContract,
18+
} from '../helpers/cli-execution.mts'
19+
20+
const RUN = ENV.RUN_E2E_TESTS
21+
22+
describe('socket threat-feed (e2e, auth required)', () => {
23+
it.skipIf(!RUN)('threat-feed --help exits 0', async () => {
24+
const result = await executeCliCommand(['threat-feed', '--help'])
25+
expect(result.code).toBe(0)
26+
})
27+
28+
it.skipIf(!RUN)('threat-feed --dry-run exits 0', async () => {
29+
const result = await executeCliCommand(['threat-feed', '--dry-run'])
30+
expect(result.code).toBe(0)
31+
})
32+
33+
it.skipIf(!RUN)('threat-feed (interactive default) exits 0', async () => {
34+
const result = await executeCliCommand(['threat-feed'])
35+
expect(result.code).toBe(0)
36+
})
37+
38+
it.skipIf(!RUN)('threat-feed --no-interactive exits 0', async () => {
39+
const result = await executeCliCommand(['threat-feed', '--no-interactive'])
40+
expect(result.code).toBe(0)
41+
})
42+
43+
it.skipIf(!RUN)('threat-feed --json conforms to contract', async () => {
44+
const result = await executeCliCommand(['threat-feed', '--json'])
45+
expect(result.code).toBe(0)
46+
validateSocketJsonContract(result.stdout, 0)
47+
})
48+
49+
it.skipIf(!RUN)('threat-feed --markdown exits 0', async () => {
50+
const result = await executeCliCommand(['threat-feed', '--markdown'])
51+
expect(result.code).toBe(0)
52+
})
53+
})

0 commit comments

Comments
 (0)