-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcmd-package.test.ts
More file actions
72 lines (60 loc) · 2.45 KB
/
cmd-package.test.ts
File metadata and controls
72 lines (60 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import path from 'node:path'
import { describe, expect } from 'vitest'
import constants from '../../../dist/constants.js'
import { cmdit, invokeNpm } from '../../../test/utils'
const { CLI } = constants
describe('socket package', async () => {
// Lazily access constants.rootBinPath.
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
cmdit(
['package', '--help', '--config', '{}'],
'should support --help',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(
`
"Commands relating to looking up published packages
Usage
$ socket package <command>
Commands
score [beta] Look up score for one package which reflects all of its transitive dependencies as well
shallow [beta] Look up info regarding one or more packages but not their transitives
Options
--dryRun Do input validation for a command and exit 0 when input is ok
--help Print this help
Examples
$ socket package --help"
`
)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: <redacted>"
`)
expect(code, 'help should exit with code 2').toBe(2)
expect(stderr, 'banner includes base command').toContain(
'`socket package`'
)
}
)
cmdit(
['package', '--dry-run', '--config', '{"apiToken":"anything"}'],
'should be ok with org name and id',
async cmd => {
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
expect(stdout).toMatchInlineSnapshot(
`"[DryRun]: No-op, call a sub-command; ok"`
)
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
"
_____ _ _ /---------------
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
|_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: <redacted>"
`)
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
}
)
})