|
| 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 package shallow', async () => { |
| 11 | + // Lazily access constants.rootBinPath. |
| 12 | + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) |
| 13 | + |
| 14 | + cmdit( |
| 15 | + ['package', 'shallow', '--help'], |
| 16 | + 'should support --help', |
| 17 | + async cmd => { |
| 18 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 19 | + expect(stdout).toMatchInlineSnapshot( |
| 20 | + ` |
| 21 | + "Look up info regarding one or more packages but not their transitives |
| 22 | +
|
| 23 | + Usage |
| 24 | + $ socket package shallow <<ecosystem> <name> [<name> ...] | <purl> [<purl> ...]> |
| 25 | +
|
| 26 | + Options |
| 27 | + --dryRun Do input validation for a command and exit 0 when input is ok |
| 28 | + --help Print this help. |
| 29 | + --json Output result as json |
| 30 | + --markdown Output result as markdown |
| 31 | +
|
| 32 | + Requirements |
| 33 | + - quota: 100 |
| 34 | + - scope: \`packages:list\` |
| 35 | +
|
| 36 | + Show scoring details for one or more packages purely based on their own package. |
| 37 | + This means that any dependency scores are not reflected by the score. You can |
| 38 | + use the \`socket package score <pkg>\` command to get its full transitive score. |
| 39 | +
|
| 40 | + Only a few ecosystems are supported like npm, golang, and maven. |
| 41 | +
|
| 42 | + A "purl" is a standard package name formatting: \`pkg:eco/name@version\` |
| 43 | + This command will automatically prepend "pkg:" when not present. |
| 44 | +
|
| 45 | + If the first arg is an ecosystem, remaining args that are not a purl are |
| 46 | + assumed to be scoped to that ecosystem. |
| 47 | +
|
| 48 | + Examples |
| 49 | + $ socket package shallow npm webtorrent |
| 50 | + $ socket package shallow npm webtorrent@1.9.1 |
| 51 | + $ socket package shallow npm/webtorrent@1.9.1 |
| 52 | + $ socket package shallow pkg:npm/webtorrent@1.9.1 |
| 53 | + $ socket package shallow maven webtorrent babel |
| 54 | + $ socket package shallow npm/webtorrent golang/babel |
| 55 | + $ socket package shallow npm npm/webtorrent@1.0.1 babel" |
| 56 | + ` |
| 57 | + ) |
| 58 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 59 | + " |
| 60 | + _____ _ _ /--------------- |
| 61 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 62 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 63 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted>" |
| 64 | + `) |
| 65 | + |
| 66 | + expect(code, 'help should exit with code 2').toBe(2) |
| 67 | + expect( |
| 68 | + stderr, |
| 69 | + 'header should include command (without params)' |
| 70 | + ).toContain('`socket package shallow`') |
| 71 | + } |
| 72 | + ) |
| 73 | + |
| 74 | + cmdit( |
| 75 | + ['package', 'shallow', '--dry-run'], |
| 76 | + 'should require args with just dry-run', |
| 77 | + async cmd => { |
| 78 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 79 | + expect(stdout).toMatchInlineSnapshot(`""`) |
| 80 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 81 | + " |
| 82 | + _____ _ _ /--------------- |
| 83 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 84 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 85 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted> |
| 86 | +
|
| 87 | + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: |
| 88 | +
|
| 89 | + - First parameter should be an ecosystem or all args must be purls \\x1b[31m(bad!)\\x1b[39m |
| 90 | +
|
| 91 | + - Expecting at least one package \\x1b[31m(missing!)\\x1b[39m" |
| 92 | + `) |
| 93 | + |
| 94 | + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) |
| 95 | + } |
| 96 | + ) |
| 97 | + |
| 98 | + cmdit( |
| 99 | + ['package', 'shallow', 'npm', 'babel', '--dry-run'], |
| 100 | + 'should require args with just dry-run', |
| 101 | + async cmd => { |
| 102 | + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) |
| 103 | + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) |
| 104 | + expect(`\n ${stderr}`).toMatchInlineSnapshot(` |
| 105 | + " |
| 106 | + _____ _ _ /--------------- |
| 107 | + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted> |
| 108 | + |__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted> |
| 109 | + |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted>" |
| 110 | + `) |
| 111 | + |
| 112 | + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) |
| 113 | + } |
| 114 | + ) |
| 115 | +}) |
0 commit comments