Skip to content

Commit 99bb776

Browse files
committed
test(e2e): port package-manager wrappers section of smoke.sh
Single file covering npm / npx / raw-npm / raw-npx / wrapper / optimize / cdxgen sections of smoke.sh, plus the 'organization dependencies' section (which logically belongs with the package-manager wrappers). wrapper on / off and optimize variants run inside executeCliInScratch (with a seeded package.json where needed) so the developer's real shim install + node_modules aren't touched.
1 parent d791885 commit 99bb776

1 file changed

Lines changed: 228 additions & 0 deletions

File tree

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/**
2+
* @file E2E tests for Socket CLI's package-manager wrappers. Ported from
3+
* `packages/cli/test/smoke.sh`'s npm / npx / raw-npm / raw-npx / wrapper /
4+
* optimize / cdxgen / dependencies sections.
5+
*
6+
* Covers: help / dry-run paths for each wrapper; the wrapper on/off
7+
* toggle (scratch-isolated so the developer's real shim install isn't
8+
* touched); `dependencies` listing + pagination flags; `cdxgen`'s
9+
* no-arg invocation; `optimize` flag matrix.
10+
*
11+
* Gated on `RUN_E2E_TESTS=1`. `dependencies` against the org list needs
12+
* auth; `cdxgen` needs a real cdxgen install on PATH.
13+
*/
14+
15+
import { describe, expect, it } from 'vitest'
16+
17+
import { ENV } from '../../src/constants/env.mts'
18+
import {
19+
executeCliCommand,
20+
executeCliInScratch,
21+
validateSocketJsonContract,
22+
} from '../helpers/cli-execution.mts'
23+
24+
const RUN = ENV.RUN_E2E_TESTS
25+
26+
describe('socket npm wrapper (e2e)', () => {
27+
it.skipIf(!RUN)('npm --help exits 0', async () => {
28+
const result = await executeCliCommand(['npm', '--help'])
29+
expect(result.code).toBe(0)
30+
})
31+
32+
it.skipIf(!RUN)('npm --dry-run exits 0', async () => {
33+
const result = await executeCliCommand(['npm', '--dry-run'])
34+
expect(result.code).toBe(0)
35+
})
36+
37+
it.skipIf(!RUN)('npm info exits 0', async () => {
38+
const result = await executeCliCommand(['npm', 'info'])
39+
expect(result.code).toBe(0)
40+
})
41+
})
42+
43+
describe('socket npx wrapper (e2e)', () => {
44+
it.skipIf(!RUN)('npx --help exits 0', async () => {
45+
const result = await executeCliCommand(['npx', '--help'])
46+
expect(result.code).toBe(0)
47+
})
48+
49+
it.skipIf(!RUN)('npx --dry-run exits 0', async () => {
50+
const result = await executeCliCommand(['npx', '--dry-run'])
51+
expect(result.code).toBe(0)
52+
})
53+
54+
it.skipIf(!RUN)('npx cowsay moo exits 0', async () => {
55+
const result = await executeCliCommand(['npx', 'cowsay', 'moo'])
56+
expect(result.code).toBe(0)
57+
})
58+
59+
it.skipIf(!RUN)('npx socket --dry-run exits 0', async () => {
60+
const result = await executeCliCommand(['npx', 'socket', '--dry-run'])
61+
expect(result.code).toBe(0)
62+
})
63+
})
64+
65+
describe('socket raw-npm (e2e)', () => {
66+
it.skipIf(!RUN)('raw-npm (no args) exits 1', async () => {
67+
const result = await executeCliCommand(['raw-npm'])
68+
expect(result.code).toBe(1)
69+
})
70+
71+
it.skipIf(!RUN)('raw-npm --help exits 0', async () => {
72+
const result = await executeCliCommand(['raw-npm', '--help'])
73+
expect(result.code).toBe(0)
74+
})
75+
76+
it.skipIf(!RUN)('raw-npm --dry-run exits 0', async () => {
77+
const result = await executeCliCommand(['raw-npm', '--dry-run'])
78+
expect(result.code).toBe(0)
79+
})
80+
81+
it.skipIf(!RUN)('raw-npm info exits 0', async () => {
82+
const result = await executeCliCommand(['raw-npm', 'info'])
83+
expect(result.code).toBe(0)
84+
})
85+
})
86+
87+
describe('socket raw-npx (e2e)', () => {
88+
it.skipIf(!RUN)('raw-npx --help exits 0', async () => {
89+
const result = await executeCliCommand(['raw-npx', '--help'])
90+
expect(result.code).toBe(0)
91+
})
92+
93+
it.skipIf(!RUN)('raw-npx --dry-run exits 0', async () => {
94+
const result = await executeCliCommand(['raw-npx', '--dry-run'])
95+
expect(result.code).toBe(0)
96+
})
97+
98+
it.skipIf(!RUN)('raw-npx cowsay moo exits 0', async () => {
99+
const result = await executeCliCommand(['raw-npx', 'cowsay', 'moo'])
100+
expect(result.code).toBe(0)
101+
})
102+
103+
it.skipIf(!RUN)('raw-npx socket --dry-run exits 0', async () => {
104+
const result = await executeCliCommand(['raw-npx', 'socket', '--dry-run'])
105+
expect(result.code).toBe(0)
106+
})
107+
})
108+
109+
describe('socket wrapper toggle (e2e, scratch-isolated)', () => {
110+
it.skipIf(!RUN)('wrapper (no subcommand) exits 2', async () => {
111+
const result = await executeCliCommand(['wrapper'])
112+
expect(result.code).toBe(2)
113+
})
114+
115+
it.skipIf(!RUN)('wrapper --help exits 0', async () => {
116+
const result = await executeCliCommand(['wrapper', '--help'])
117+
expect(result.code).toBe(0)
118+
})
119+
120+
it.skipIf(!RUN)('wrapper --dry-run (no on/off) exits 2', async () => {
121+
const result = await executeCliCommand(['wrapper', '--dry-run'])
122+
expect(result.code).toBe(2)
123+
})
124+
125+
it.skipIf(!RUN)('wrapper on exits 0', async () => {
126+
const result = await executeCliInScratch(['wrapper', 'on'])
127+
expect(result.code).toBe(0)
128+
})
129+
130+
it.skipIf(!RUN)('wrapper off exits 0', async () => {
131+
const result = await executeCliInScratch(['wrapper', 'off'])
132+
expect(result.code).toBe(0)
133+
})
134+
})
135+
136+
describe('socket optimize (e2e)', () => {
137+
it.skipIf(!RUN)('optimize --help exits 0', async () => {
138+
const result = await executeCliCommand(['optimize', '--help'])
139+
expect(result.code).toBe(0)
140+
})
141+
142+
it.skipIf(!RUN)('optimize --dry-run exits 0', async () => {
143+
const result = await executeCliCommand(['optimize', '--dry-run'])
144+
expect(result.code).toBe(0)
145+
})
146+
147+
it.skipIf(!RUN)('optimize exits 0', async () => {
148+
const result = await executeCliInScratch(['optimize'], {
149+
seedFiles: {
150+
'package.json': JSON.stringify({ name: 'socket-cli-e2e-optimize', version: '0.0.0' }),
151+
},
152+
})
153+
expect(result.code).toBe(0)
154+
})
155+
156+
it.skipIf(!RUN)('optimize --prod exits 0', async () => {
157+
const result = await executeCliInScratch(['optimize', '--prod'], {
158+
seedFiles: {
159+
'package.json': JSON.stringify({ name: 'socket-cli-e2e-optimize', version: '0.0.0' }),
160+
},
161+
})
162+
expect(result.code).toBe(0)
163+
})
164+
165+
it.skipIf(!RUN)('optimize --pin exits 0', async () => {
166+
const result = await executeCliInScratch(['optimize', '--pin'], {
167+
seedFiles: {
168+
'package.json': JSON.stringify({ name: 'socket-cli-e2e-optimize', version: '0.0.0' }),
169+
},
170+
})
171+
expect(result.code).toBe(0)
172+
})
173+
})
174+
175+
describe('socket cdxgen (e2e)', () => {
176+
it.skipIf(!RUN)('cdxgen (no args, no real cdxgen on PATH) exits 1', async () => {
177+
const result = await executeCliCommand(['cdxgen'])
178+
expect(result.code).toBe(1)
179+
})
180+
})
181+
182+
describe('socket organization dependencies (e2e, auth required)', () => {
183+
it.skipIf(!RUN)('organization dependencies --help exits 0', async () => {
184+
const result = await executeCliCommand(['organization', 'dependencies', '--help'])
185+
expect(result.code).toBe(0)
186+
})
187+
188+
it.skipIf(!RUN)('organization dependencies --dry-run exits 0', async () => {
189+
const result = await executeCliCommand(['organization', 'dependencies', '--dry-run'])
190+
expect(result.code).toBe(0)
191+
})
192+
193+
it.skipIf(!RUN)('organization dependencies exits 0', async () => {
194+
const result = await executeCliCommand(['organization', 'dependencies'])
195+
expect(result.code).toBe(0)
196+
})
197+
198+
it.skipIf(!RUN)('organization dependencies --json conforms to contract', async () => {
199+
const result = await executeCliCommand(['organization', 'dependencies', '--json'])
200+
expect(result.code).toBe(0)
201+
validateSocketJsonContract(result.stdout, 0)
202+
})
203+
204+
it.skipIf(!RUN)('organization dependencies --markdown exits 0', async () => {
205+
const result = await executeCliCommand(['organization', 'dependencies', '--markdown'])
206+
expect(result.code).toBe(0)
207+
})
208+
209+
it.skipIf(!RUN)('organization dependencies --limit 1 exits 0', async () => {
210+
const result = await executeCliCommand(['organization', 'dependencies', '--limit', '1'])
211+
expect(result.code).toBe(0)
212+
})
213+
214+
it.skipIf(!RUN)('organization dependencies --offset 5 exits 0', async () => {
215+
const result = await executeCliCommand(['organization', 'dependencies', '--offset', '5'])
216+
expect(result.code).toBe(0)
217+
})
218+
219+
it.skipIf(!RUN)(
220+
'organization dependencies --limit 1 --offset 10 exits 0',
221+
async () => {
222+
const result = await executeCliCommand([
223+
'organization', 'dependencies', '--limit', '1', '--offset', '10',
224+
])
225+
expect(result.code).toBe(0)
226+
},
227+
)
228+
})

0 commit comments

Comments
 (0)