Skip to content

Commit ebded16

Browse files
committed
test(cli): add unit tests for barrel file exports
Add tests for re-export barrel files: - constants-root-barrel.test.mts: 35 tests for root constants.mts barrel - registry-barrel.test.mts: 15 tests for command registry barrel exports - standalone.test.mts: Expanded python/standalone barrel tests
1 parent 46a4b31 commit ebded16

File tree

3 files changed

+541
-0
lines changed

3 files changed

+541
-0
lines changed
Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,366 @@
1+
/**
2+
* Unit tests for root constants barrel file.
3+
*
4+
* Purpose:
5+
* Tests the root constants.mts barrel file exports.
6+
*
7+
* Test Coverage:
8+
* - Named exports verification
9+
* - Default export verification
10+
* - Key constants values
11+
*
12+
* Related Files:
13+
* - src/constants.mts (implementation)
14+
* - src/constants/*.mts (source modules)
15+
*/
16+
17+
import { describe, expect, it } from 'vitest'
18+
19+
import constants, {
20+
// Agent constants.
21+
BUN,
22+
getMinimumVersionByAgent,
23+
getNpmExecPath,
24+
getPnpmExecPath,
25+
NPM,
26+
NPX,
27+
PNPM,
28+
VLT,
29+
YARN,
30+
YARN_BERRY,
31+
YARN_CLASSIC,
32+
// Alert type constants.
33+
ALERT_TYPE_CRITICAL_CVE,
34+
ALERT_TYPE_CVE,
35+
ALERT_TYPE_MEDIUM_CVE,
36+
ALERT_TYPE_MILD_CVE,
37+
// Cache constants.
38+
DLX_BINARY_CACHE_TTL,
39+
UPDATE_CHECK_TTL,
40+
UPDATE_NOTIFIER_TIMEOUT,
41+
// CLI constants.
42+
DRY_RUN_BAILING_NOW,
43+
DRY_RUN_LABEL,
44+
DRY_RUN_NOT_SAVING,
45+
FLAG_CONFIG,
46+
FLAG_DRY_RUN,
47+
FLAG_HELP,
48+
FLAG_JSON,
49+
FLAG_ORG,
50+
FLAG_QUIET,
51+
FLAG_VERBOSE,
52+
FOLD_SETTING_FILE,
53+
FOLD_SETTING_NONE,
54+
FOLD_SETTING_PKG,
55+
FOLD_SETTING_VERSION,
56+
OUTPUT_JSON,
57+
OUTPUT_MARKDOWN,
58+
OUTPUT_TEXT,
59+
SEA_UPDATE_COMMAND,
60+
// Config constants.
61+
CONFIG_KEY_API_BASE_URL,
62+
CONFIG_KEY_API_PROXY,
63+
CONFIG_KEY_API_TOKEN,
64+
CONFIG_KEY_DEFAULT_ORG,
65+
CONFIG_KEY_ENFORCED_ORGS,
66+
CONFIG_KEY_ORG,
67+
// Error constants.
68+
ERROR_NO_MANIFEST_FILES,
69+
ERROR_NO_PACKAGE_JSON,
70+
ERROR_NO_REPO_FOUND,
71+
ERROR_NO_SOCKET_DIR,
72+
ERROR_UNABLE_RESOLVE_ORG,
73+
LOOP_SENTINEL,
74+
// GitHub constants.
75+
GQL_PAGE_SENTINEL,
76+
GQL_PR_STATE_CLOSED,
77+
GQL_PR_STATE_MERGED,
78+
GQL_PR_STATE_OPEN,
79+
SOCKET_CLI_GITHUB_REPO,
80+
// HTTP constants.
81+
HTTP_STATUS_BAD_REQUEST,
82+
HTTP_STATUS_FORBIDDEN,
83+
HTTP_STATUS_INTERNAL_SERVER_ERROR,
84+
HTTP_STATUS_NOT_FOUND,
85+
HTTP_STATUS_TOO_MANY_REQUESTS,
86+
HTTP_STATUS_UNAUTHORIZED,
87+
NPM_REGISTRY_URL,
88+
// Package constants.
89+
EXT_LOCK,
90+
EXT_LOCKB,
91+
NODE_MODULES,
92+
PACKAGE_JSON,
93+
PACKAGE_LOCK_JSON,
94+
PNPM_LOCK_YAML,
95+
SOCKET_CLI_BIN_NAME,
96+
SOCKET_CLI_PACKAGE_NAME,
97+
YARN_LOCK,
98+
// Path constants.
99+
configPath,
100+
distPath,
101+
execPath,
102+
externalPath,
103+
getCliVersion,
104+
homePath,
105+
rootPath,
106+
srcPath,
107+
// Socket constants.
108+
API_V0_URL,
109+
SCAN_TYPE_SOCKET,
110+
SCAN_TYPE_SOCKET_TIER1,
111+
SOCKET_CLI_ISSUES_URL,
112+
SOCKET_DEFAULT_BRANCH,
113+
SOCKET_DEFAULT_REPOSITORY,
114+
SOCKET_WEBSITE_URL,
115+
TOKEN_PREFIX,
116+
TOKEN_PREFIX_LENGTH,
117+
// Type constants.
118+
WIN32,
119+
// Env constants.
120+
VITEST,
121+
} from '../../src/constants.mts'
122+
123+
describe('constants root barrel exports', () => {
124+
describe('agent constants', () => {
125+
it('exports agent name constants', () => {
126+
expect(NPM).toBe('npm')
127+
expect(NPX).toBe('npx')
128+
expect(PNPM).toBe('pnpm')
129+
expect(YARN).toBe('yarn')
130+
expect(BUN).toBe('bun')
131+
expect(VLT).toBe('vlt')
132+
expect(YARN_CLASSIC).toBe('yarn/classic')
133+
expect(YARN_BERRY).toBe('yarn/berry')
134+
})
135+
136+
it('exports agent utility functions', () => {
137+
expect(typeof getMinimumVersionByAgent).toBe('function')
138+
expect(typeof getNpmExecPath).toBe('function')
139+
expect(typeof getPnpmExecPath).toBe('function')
140+
})
141+
})
142+
143+
describe('alert type constants', () => {
144+
it('exports alert types', () => {
145+
expect(ALERT_TYPE_CVE).toBe('cve')
146+
expect(ALERT_TYPE_CRITICAL_CVE).toBe('criticalCVE')
147+
expect(ALERT_TYPE_MEDIUM_CVE).toBe('mediumCVE')
148+
expect(ALERT_TYPE_MILD_CVE).toBe('mildCVE')
149+
})
150+
})
151+
152+
describe('cache constants', () => {
153+
it('exports cache TTL values as numbers', () => {
154+
expect(typeof DLX_BINARY_CACHE_TTL).toBe('number')
155+
expect(typeof UPDATE_CHECK_TTL).toBe('number')
156+
expect(typeof UPDATE_NOTIFIER_TIMEOUT).toBe('number')
157+
})
158+
159+
it('cache TTLs are positive', () => {
160+
expect(DLX_BINARY_CACHE_TTL).toBeGreaterThan(0)
161+
expect(UPDATE_CHECK_TTL).toBeGreaterThan(0)
162+
expect(UPDATE_NOTIFIER_TIMEOUT).toBeGreaterThan(0)
163+
})
164+
})
165+
166+
describe('CLI flag constants', () => {
167+
it('exports flag constants with -- prefix', () => {
168+
expect(FLAG_DRY_RUN).toBe('--dry-run')
169+
expect(FLAG_HELP).toBe('--help')
170+
expect(FLAG_JSON).toBe('--json')
171+
expect(FLAG_ORG).toBe('--org')
172+
expect(FLAG_QUIET).toBe('--quiet')
173+
expect(FLAG_VERBOSE).toBe('--verbose')
174+
expect(FLAG_CONFIG).toBe('--config')
175+
})
176+
177+
it('exports output format constants', () => {
178+
expect(OUTPUT_JSON).toBe('json')
179+
expect(OUTPUT_MARKDOWN).toBe('markdown')
180+
expect(OUTPUT_TEXT).toBe('text')
181+
})
182+
183+
it('exports fold setting constants', () => {
184+
expect(typeof FOLD_SETTING_FILE).toBe('string')
185+
expect(typeof FOLD_SETTING_NONE).toBe('string')
186+
expect(typeof FOLD_SETTING_PKG).toBe('string')
187+
expect(typeof FOLD_SETTING_VERSION).toBe('string')
188+
})
189+
190+
it('exports dry run message constants', () => {
191+
expect(typeof DRY_RUN_BAILING_NOW).toBe('string')
192+
expect(typeof DRY_RUN_LABEL).toBe('string')
193+
expect(typeof DRY_RUN_NOT_SAVING).toBe('string')
194+
})
195+
196+
it('exports SEA update command', () => {
197+
expect(SEA_UPDATE_COMMAND).toBe('self-update')
198+
})
199+
})
200+
201+
describe('config key constants', () => {
202+
it('exports config key constants', () => {
203+
expect(CONFIG_KEY_API_BASE_URL).toBe('apiBaseUrl')
204+
expect(CONFIG_KEY_API_PROXY).toBe('apiProxy')
205+
expect(CONFIG_KEY_API_TOKEN).toBe('apiToken')
206+
expect(CONFIG_KEY_DEFAULT_ORG).toBe('defaultOrg')
207+
expect(CONFIG_KEY_ENFORCED_ORGS).toBe('enforcedOrgs')
208+
expect(CONFIG_KEY_ORG).toBe('org')
209+
})
210+
})
211+
212+
describe('error constants', () => {
213+
it('exports error message constants', () => {
214+
expect(typeof ERROR_NO_MANIFEST_FILES).toBe('string')
215+
expect(typeof ERROR_NO_PACKAGE_JSON).toBe('string')
216+
expect(typeof ERROR_NO_REPO_FOUND).toBe('string')
217+
expect(typeof ERROR_NO_SOCKET_DIR).toBe('string')
218+
expect(typeof ERROR_UNABLE_RESOLVE_ORG).toBe('string')
219+
})
220+
221+
it('exports loop sentinel as a number', () => {
222+
expect(typeof LOOP_SENTINEL).toBe('number')
223+
expect(LOOP_SENTINEL).toBeGreaterThan(0)
224+
})
225+
})
226+
227+
describe('GitHub constants', () => {
228+
it('exports GraphQL pagination sentinel', () => {
229+
expect(typeof GQL_PAGE_SENTINEL).toBe('number')
230+
})
231+
232+
it('exports PR state constants', () => {
233+
expect(GQL_PR_STATE_OPEN).toBe('OPEN')
234+
expect(GQL_PR_STATE_CLOSED).toBe('CLOSED')
235+
expect(GQL_PR_STATE_MERGED).toBe('MERGED')
236+
})
237+
238+
it('exports GitHub repo name', () => {
239+
expect(SOCKET_CLI_GITHUB_REPO).toBe('socket-cli')
240+
})
241+
})
242+
243+
describe('HTTP constants', () => {
244+
it('exports HTTP status codes', () => {
245+
expect(HTTP_STATUS_BAD_REQUEST).toBe(400)
246+
expect(HTTP_STATUS_UNAUTHORIZED).toBe(401)
247+
expect(HTTP_STATUS_FORBIDDEN).toBe(403)
248+
expect(HTTP_STATUS_NOT_FOUND).toBe(404)
249+
expect(HTTP_STATUS_TOO_MANY_REQUESTS).toBe(429)
250+
expect(HTTP_STATUS_INTERNAL_SERVER_ERROR).toBe(500)
251+
})
252+
253+
it('exports npm registry URL', () => {
254+
expect(NPM_REGISTRY_URL).toBe('https://registry.npmjs.org')
255+
})
256+
})
257+
258+
describe('package constants', () => {
259+
it('exports file name constants', () => {
260+
expect(PACKAGE_JSON).toBe('package.json')
261+
expect(PACKAGE_LOCK_JSON).toBe('package-lock.json')
262+
expect(PNPM_LOCK_YAML).toBe('pnpm-lock.yaml')
263+
expect(YARN_LOCK).toBe('yarn.lock')
264+
expect(NODE_MODULES).toBe('node_modules')
265+
})
266+
267+
it('exports extension constants', () => {
268+
expect(EXT_LOCK).toBe('.lock')
269+
expect(EXT_LOCKB).toBe('.lockb')
270+
})
271+
272+
it('exports socket CLI name constants', () => {
273+
expect(SOCKET_CLI_BIN_NAME).toBe('socket')
274+
expect(SOCKET_CLI_PACKAGE_NAME).toBe('socket')
275+
})
276+
})
277+
278+
describe('path constants', () => {
279+
it('exports path values as strings', () => {
280+
expect(typeof configPath).toBe('string')
281+
expect(typeof distPath).toBe('string')
282+
expect(typeof execPath).toBe('string')
283+
expect(typeof externalPath).toBe('string')
284+
expect(typeof homePath).toBe('string')
285+
expect(typeof rootPath).toBe('string')
286+
expect(typeof srcPath).toBe('string')
287+
})
288+
289+
it('exports getCliVersion function', () => {
290+
expect(typeof getCliVersion).toBe('function')
291+
})
292+
})
293+
294+
describe('Socket API constants', () => {
295+
it('exports API URL', () => {
296+
expect(API_V0_URL).toBe('https://api.socket.dev/v0/')
297+
})
298+
299+
it('exports scan type constants', () => {
300+
expect(SCAN_TYPE_SOCKET).toBe('socket')
301+
expect(SCAN_TYPE_SOCKET_TIER1).toBe('socket_tier1')
302+
})
303+
304+
it('exports Socket website constants', () => {
305+
expect(SOCKET_WEBSITE_URL).toBe('https://socket.dev')
306+
expect(SOCKET_CLI_ISSUES_URL).toBe(
307+
'https://github.com/SocketDev/socket-cli/issues',
308+
)
309+
})
310+
311+
it('exports default branch and repository', () => {
312+
// These are config key-like identifiers, not actual values.
313+
expect(typeof SOCKET_DEFAULT_BRANCH).toBe('string')
314+
expect(typeof SOCKET_DEFAULT_REPOSITORY).toBe('string')
315+
})
316+
317+
it('exports token constants', () => {
318+
expect(TOKEN_PREFIX).toBe('sktsec_')
319+
expect(TOKEN_PREFIX_LENGTH).toBe(7)
320+
})
321+
})
322+
323+
describe('type constants', () => {
324+
it('exports WIN32 constant', () => {
325+
// WIN32 is process.platform === 'win32' boolean on non-Windows, string on Windows.
326+
expect(typeof WIN32 === 'boolean' || typeof WIN32 === 'string').toBe(true)
327+
})
328+
})
329+
330+
describe('env constants', () => {
331+
it('exports VITEST as true in test environment', () => {
332+
expect(VITEST).toBe(true)
333+
})
334+
})
335+
336+
describe('default export', () => {
337+
it('exports an object with constants', () => {
338+
expect(typeof constants).toBe('object')
339+
expect(constants).not.toBeNull()
340+
})
341+
342+
it('includes ENV object', () => {
343+
expect(constants.ENV).toBeDefined()
344+
expect(typeof constants.ENV).toBe('object')
345+
})
346+
347+
it('includes key constants', () => {
348+
expect(constants.NPM).toBe('npm')
349+
expect(constants.PNPM).toBe('pnpm')
350+
expect(constants.YARN).toBe('yarn')
351+
expect(constants.OUTPUT_JSON).toBe('json')
352+
expect(constants.OUTPUT_TEXT).toBe('text')
353+
})
354+
355+
it('includes path constants', () => {
356+
expect(typeof constants.rootPath).toBe('string')
357+
expect(typeof constants.distPath).toBe('string')
358+
expect(typeof constants.srcPath).toBe('string')
359+
})
360+
361+
it('includes getter functions', () => {
362+
expect(typeof constants.getCliVersion).toBe('function')
363+
expect(typeof constants.getMinimumVersionByAgent).toBe('function')
364+
})
365+
})
366+
})

0 commit comments

Comments
 (0)