From f8bceff03a5ad1f8bbb18f6ab3d965dfda0fa490 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 25 Mar 2025 15:10:13 +0100 Subject: [PATCH 1/2] Allow config override through --config or env.SOCKET_CLI_CONFIG --- src/commands/analytics/cmd-analytics.test.ts | 28 +++--- src/commands/audit-log/cmd-audit-log.test.ts | 30 +++--- src/commands/cdxgen/cmd-cdxgen.test.ts | 6 +- src/commands/config/cmd-config-get.test.ts | 30 +++--- src/commands/config/cmd-config-list.test.ts | 28 +++--- src/commands/config/cmd-config-set.test.ts | 30 +++--- src/commands/config/cmd-config-unset.test.ts | 30 +++--- src/commands/config/cmd-config.test.ts | 28 +++--- .../dependencies/cmd-dependencies.test.ts | 28 +++--- .../diff-scan/cmd-diff-scan-get.test.ts | 30 +++--- src/commands/diff-scan/cmd-diff-scan.test.ts | 28 +++--- src/commands/fix/cmd-fix.test.ts | 26 ++--- src/commands/info/cmd-info.test.ts | 28 +++--- src/commands/login/cmd-login.test.ts | 26 ++--- src/commands/logout/cmd-logout.test.ts | 28 +++--- .../manifest/cmd-manifest-auto.test.ts | 28 +++--- .../manifest/cmd-manifest-gradle.test.ts | 85 ++++++++-------- .../manifest/cmd-manifest-kotlin.test.ts | 85 ++++++++-------- .../manifest/cmd-manifest-scala.test.ts | 30 +++--- src/commands/manifest/cmd-manifest.test.ts | 28 +++--- src/commands/npm/cmd-npm.test.ts | 26 ++--- src/commands/npx/cmd-npx.test.ts | 26 ++--- src/commands/oops/cmd-oops.test.ts | 26 ++--- src/commands/optimize/cmd-optimize.test.ts | 28 +++--- .../cmd-organization-list.test.ts | 53 +++++----- .../cmd-organization-policy-security.test.ts | 73 +++++++------- .../cmd-organization-policy.test.ts | 51 +++++++--- .../cmd-organization-quota.test.ts | 53 +++++----- .../organization/cmd-organization.test.ts | 28 +++--- .../package/cmd-package-shallow.test.ts | 97 +++++++++---------- src/commands/package/cmd-package.test.ts | 68 ++++++++----- src/commands/raw-npm/cmd-raw-npm.test.ts | 28 +++--- src/commands/raw-npx/cmd-raw-npx.test.ts | 28 +++--- src/commands/report/cmd-report-create.test.ts | 28 +++--- src/commands/report/cmd-report-view.test.ts | 28 +++--- src/commands/report/cmd-report.test.ts | 28 +++--- src/commands/repos/cmd-repos-create.test.ts | 95 ++++++++++++++++++ src/commands/repos/cmd-repos-del.test.ts | 92 ++++++++++++++++++ src/commands/repos/cmd-repos-list.test.ts | 96 ++++++++++++++++++ src/commands/repos/cmd-repos-update.test.ts | 97 +++++++++++++++++++ src/commands/repos/cmd-repos-view.test.ts | 93 ++++++++++++++++++ src/commands/repos/cmd-repos.test.ts | 73 ++++++++++++++ src/commands/scan/cmd-scan-create.test.ts | 65 ++++++++++--- src/commands/scan/cmd-scan-create.ts | 2 + src/commands/scan/cmd-scan-del.test.ts | 30 +++--- src/commands/scan/cmd-scan-list.test.ts | 30 +++--- src/commands/scan/cmd-scan-metadata.test.ts | 30 +++--- src/commands/scan/cmd-scan-report.test.ts | 42 ++++---- src/commands/scan/cmd-scan-view.test.ts | 30 +++--- src/commands/scan/cmd-scan.test.ts | 56 +++++------ .../threat-feed/cmd-threat-feed.test.ts | 28 +++--- src/commands/wrapper/cmd-wrapper.test.ts | 28 +++--- src/flags.ts | 11 ++- src/utils/config.ts | 14 ++- src/utils/meow-with-subcommands.ts | 62 +++++++----- src/utils/output-formatting.ts | 19 ++-- 56 files changed, 1562 insertions(+), 760 deletions(-) create mode 100644 src/commands/repos/cmd-repos-create.test.ts create mode 100644 src/commands/repos/cmd-repos-del.test.ts create mode 100644 src/commands/repos/cmd-repos-list.test.ts create mode 100644 src/commands/repos/cmd-repos-update.test.ts create mode 100644 src/commands/repos/cmd-repos-view.test.ts create mode 100644 src/commands/repos/cmd-repos.test.ts diff --git a/src/commands/analytics/cmd-analytics.test.ts b/src/commands/analytics/cmd-analytics.test.ts index 76f962436..4110f6cc1 100644 --- a/src/commands/analytics/cmd-analytics.test.ts +++ b/src/commands/analytics/cmd-analytics.test.ts @@ -11,10 +11,13 @@ describe('socket analytics', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['analytics', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['analytics', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Look up analytics data Usage @@ -38,8 +41,8 @@ describe('socket analytics', async () => { $ socket analytics --scope=org --time=30 $ socket analytics --scope=repo --repo=test-repo --time=30" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -47,14 +50,15 @@ describe('socket analytics', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket analytics`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket analytics`' + ) + } + ) cmdit( - ['analytics', '--dry-run'], + ['analytics', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/audit-log/cmd-audit-log.test.ts b/src/commands/audit-log/cmd-audit-log.test.ts index 888a411be..e1bcb3ae2 100644 --- a/src/commands/audit-log/cmd-audit-log.test.ts +++ b/src/commands/audit-log/cmd-audit-log.test.ts @@ -11,10 +11,13 @@ describe('socket audit-log', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['audit-log', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['audit-log', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Look up the audit log for an organization Usage @@ -35,8 +38,8 @@ describe('socket audit-log', async () => { Examples $ socket audit-log FakeOrg" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -44,14 +47,15 @@ describe('socket audit-log', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket audit-log`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket audit-log`' + ) + } + ) cmdit( - ['audit-log', '--dry-run'], + ['audit-log', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -73,7 +77,7 @@ describe('socket audit-log', async () => { ) cmdit( - ['audit-log', 'fakeorg', '--dry-run'], + ['audit-log', 'fakeorg', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/cdxgen/cmd-cdxgen.test.ts b/src/commands/cdxgen/cmd-cdxgen.test.ts index 462b95cb4..47f014025 100644 --- a/src/commands/cdxgen/cmd-cdxgen.test.ts +++ b/src/commands/cdxgen/cmd-cdxgen.test.ts @@ -81,14 +81,12 @@ describe('socket cdxgen', async () => { // expect(code, 'help should exit with code 2').toBe(2) expect(code, 'help should exit with code 2').toBe(0) // cdxgen special case - expect(stderr, 'header should include command (without params)').toContain( - '`socket cdxgen`' - ) + expect(stderr, 'banner includes base command').toContain('`socket cdxgen`') }) // cdxgen does not support --dry-run // cmdit( - // ['cdxgen', '--dry-run'], + // ['cdxgen', '--help', '--config', '{}'], // 'should require args with just dry-run', // async cmd => { // const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/config/cmd-config-get.test.ts b/src/commands/config/cmd-config-get.test.ts index 5924f8960..4ea26e2c9 100644 --- a/src/commands/config/cmd-config-get.test.ts +++ b/src/commands/config/cmd-config-get.test.ts @@ -11,10 +11,13 @@ describe('socket config get', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['config', 'get', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['config', 'get', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Get the value of a local CLI config item Usage @@ -36,8 +39,8 @@ describe('socket config get', async () => { Examples $ socket config get FakeOrg --repoName=test-repo" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -45,14 +48,15 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket config get`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket config get`' + ) + } + ) cmdit( - ['config', 'get', '--dry-run'], + ['config', 'get', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -74,7 +78,7 @@ describe('socket config get', async () => { ) cmdit( - ['config', 'get', 'test', '--dry-run'], + ['config', 'get', 'test', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/config/cmd-config-list.test.ts b/src/commands/config/cmd-config-list.test.ts index c42a1a7d6..c5a2b63b2 100644 --- a/src/commands/config/cmd-config-list.test.ts +++ b/src/commands/config/cmd-config-list.test.ts @@ -11,10 +11,13 @@ describe('socket config get', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['config', 'list', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['config', 'list', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Show all local CLI config items and their values Usage @@ -37,8 +40,8 @@ describe('socket config get', async () => { Examples $ socket config list FakeOrg --repoName=test-repo" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -46,14 +49,15 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket config list`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket config list`' + ) + } + ) cmdit( - ['config', 'list', '--dry-run'], + ['config', 'list', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/config/cmd-config-set.test.ts b/src/commands/config/cmd-config-set.test.ts index e6764039a..87407993b 100644 --- a/src/commands/config/cmd-config-set.test.ts +++ b/src/commands/config/cmd-config-set.test.ts @@ -11,10 +11,13 @@ describe('socket config get', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['config', 'set', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['config', 'set', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Update the value of a local CLI config item Usage @@ -41,8 +44,8 @@ describe('socket config get', async () => { Examples $ socket config set apiProxy https://example.com" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -50,14 +53,15 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config set\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket config set`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket config set`' + ) + } + ) cmdit( - ['config', 'set', '--dry-run'], + ['config', 'set', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -81,7 +85,7 @@ describe('socket config get', async () => { ) cmdit( - ['config', 'set', 'test', 'xyz', '--dry-run'], + ['config', 'set', 'test', 'xyz', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/config/cmd-config-unset.test.ts b/src/commands/config/cmd-config-unset.test.ts index 6cc259859..c8bffb8a0 100644 --- a/src/commands/config/cmd-config-unset.test.ts +++ b/src/commands/config/cmd-config-unset.test.ts @@ -11,10 +11,13 @@ describe('socket config unset', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['config', 'unset', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['config', 'unset', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Clear the value of a local CLI config item Usage @@ -36,8 +39,8 @@ describe('socket config unset', async () => { Examples $ socket config unset FakeOrg --repoName=test-repo" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -45,14 +48,15 @@ describe('socket config unset', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config unset\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket config unset`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket config unset`' + ) + } + ) cmdit( - ['config', 'unset', '--dry-run'], + ['config', 'unset', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -74,7 +78,7 @@ describe('socket config unset', async () => { ) cmdit( - ['config', 'unset', 'test', '--dry-run'], + ['config', 'unset', 'test', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/config/cmd-config.test.ts b/src/commands/config/cmd-config.test.ts index cdd00227b..c0d9b5433 100644 --- a/src/commands/config/cmd-config.test.ts +++ b/src/commands/config/cmd-config.test.ts @@ -11,10 +11,13 @@ describe('socket config', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['config', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['config', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Commands related to the local CLI configuration Usage @@ -33,8 +36,8 @@ describe('socket config', async () => { Examples $ socket config --help" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -42,14 +45,15 @@ describe('socket config', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket config`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket config`' + ) + } + ) cmdit( - ['config', '--dry-run'], + ['config', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/dependencies/cmd-dependencies.test.ts b/src/commands/dependencies/cmd-dependencies.test.ts index 493a9823b..8d8724401 100644 --- a/src/commands/dependencies/cmd-dependencies.test.ts +++ b/src/commands/dependencies/cmd-dependencies.test.ts @@ -11,10 +11,13 @@ describe('socket dependencies', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['dependencies', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['dependencies', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Search for any dependency that is being used in your organization Usage @@ -31,8 +34,8 @@ describe('socket dependencies', async () => { Examples socket dependencies --limit 20 --offset 10" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -40,14 +43,15 @@ describe('socket dependencies', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket dependencies\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket dependencies`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket dependencies`' + ) + } + ) cmdit( - ['dependencies', '--dry-run'], + ['dependencies', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/diff-scan/cmd-diff-scan-get.test.ts b/src/commands/diff-scan/cmd-diff-scan-get.test.ts index d59fd6ea2..0216f1f0b 100644 --- a/src/commands/diff-scan/cmd-diff-scan-get.test.ts +++ b/src/commands/diff-scan/cmd-diff-scan-get.test.ts @@ -11,10 +11,13 @@ describe('socket diff-scan get', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['diff-scan', 'get', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['diff-scan', 'get', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Get a diff scan for an organization Usage @@ -36,8 +39,8 @@ describe('socket diff-scan get', async () => { Examples $ socket diff-scan get FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -45,14 +48,15 @@ describe('socket diff-scan get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan get\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket diff-scan get`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket diff-scan get`' + ) + } + ) cmdit( - ['diff-scan', 'get', '--dry-run'], + ['diff-scan', 'get', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -84,6 +88,8 @@ describe('socket diff-scan get', async () => { 'get', 'fakeorg', '--dry-run', + '--config', + '{}', '--before', 'x', '--after', diff --git a/src/commands/diff-scan/cmd-diff-scan.test.ts b/src/commands/diff-scan/cmd-diff-scan.test.ts index c867eef0e..ee48cfa88 100644 --- a/src/commands/diff-scan/cmd-diff-scan.test.ts +++ b/src/commands/diff-scan/cmd-diff-scan.test.ts @@ -11,10 +11,13 @@ describe('socket diff-scan', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['diff-scan', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['diff-scan', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Diff scans related commands Usage @@ -30,8 +33,8 @@ describe('socket diff-scan', async () => { Examples $ socket diff-scan --help" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,14 +42,15 @@ describe('socket diff-scan', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket diff-scan`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket diff-scan`' + ) + } + ) cmdit( - ['diff-scan', '--dry-run'], + ['diff-scan', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/fix/cmd-fix.test.ts b/src/commands/fix/cmd-fix.test.ts index 5cf0c3270..2fb22c074 100644 --- a/src/commands/fix/cmd-fix.test.ts +++ b/src/commands/fix/cmd-fix.test.ts @@ -11,10 +11,13 @@ describe('socket fix', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['fix', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['fix', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Fix "fixable" Socket alerts Usage @@ -24,8 +27,8 @@ describe('socket fix', async () => { --dryRun Do input validation for a command and exit 0 when input is ok --help Print this help." ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -33,14 +36,13 @@ describe('socket fix', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket fix\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket fix`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket fix`') + } + ) cmdit( - ['fix', '--dry-run'], + ['fix', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/info/cmd-info.test.ts b/src/commands/info/cmd-info.test.ts index e291cc807..70148c089 100644 --- a/src/commands/info/cmd-info.test.ts +++ b/src/commands/info/cmd-info.test.ts @@ -11,10 +11,13 @@ describe('socket info', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['info', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['info', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Look up info regarding a package Usage @@ -32,8 +35,8 @@ describe('socket info', async () => { $ socket info webtorrent $ socket info webtorrent@1.9.1" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -41,14 +44,13 @@ describe('socket info', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket info\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket info`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket info`') + } + ) cmdit( - ['info', '--dry-run'], + ['info', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -72,7 +74,7 @@ describe('socket info', async () => { ) cmdit( - ['info', 'mootools', '--dry-run'], + ['info', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/login/cmd-login.test.ts b/src/commands/login/cmd-login.test.ts index dce90acc7..534fcf18a 100644 --- a/src/commands/login/cmd-login.test.ts +++ b/src/commands/login/cmd-login.test.ts @@ -11,10 +11,13 @@ describe('socket login', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['login', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['login', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Socket API login Usage @@ -32,8 +35,8 @@ describe('socket login', async () => { $ socket login $ socket login --api-proxy=http://localhost:1234" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -41,14 +44,13 @@ describe('socket login', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket login\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket login`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket login`') + } + ) cmdit( - ['login', 'mootools', '--dry-run'], + ['login', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/logout/cmd-logout.test.ts b/src/commands/logout/cmd-logout.test.ts index d1db72ef7..c097f4b02 100644 --- a/src/commands/logout/cmd-logout.test.ts +++ b/src/commands/logout/cmd-logout.test.ts @@ -11,10 +11,13 @@ describe('socket logout', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['logout', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['logout', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Socket API logout Usage @@ -22,8 +25,8 @@ describe('socket logout', async () => { Logs out of the Socket API and clears all Socket credentials from disk" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -31,14 +34,15 @@ describe('socket logout', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket logout\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket logout`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket logout`' + ) + } + ) cmdit( - ['logout', 'mootools', '--dry-run'], + ['logout', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/manifest/cmd-manifest-auto.test.ts b/src/commands/manifest/cmd-manifest-auto.test.ts index 502b5a9f5..3610ea7e2 100644 --- a/src/commands/manifest/cmd-manifest-auto.test.ts +++ b/src/commands/manifest/cmd-manifest-auto.test.ts @@ -11,10 +11,13 @@ describe('socket manifest auto', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['manifest', 'auto', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['manifest', 'auto', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Auto-detect build and attempt to generate manifest file Usage @@ -30,8 +33,8 @@ describe('socket manifest auto', async () => { supported case then it will try to generate the manifest file for that language with the default or detected settings." ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,14 +42,15 @@ describe('socket manifest auto', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest auto\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket manifest auto`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket manifest auto`' + ) + } + ) cmdit( - ['manifest', 'auto', '--dry-run'], + ['manifest', 'auto', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/manifest/cmd-manifest-gradle.test.ts b/src/commands/manifest/cmd-manifest-gradle.test.ts index c6fd8c27c..d18eb50ee 100644 --- a/src/commands/manifest/cmd-manifest-gradle.test.ts +++ b/src/commands/manifest/cmd-manifest-gradle.test.ts @@ -12,72 +12,71 @@ describe('socket manifest gradle', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['manifest', 'gradle', '--help'], + ['manifest', 'gradle', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "[beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Gradle/Java/Kotlin/etc project + "[beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Gradle/Java/Kotlin/etc project - Usage - $ socket manifest gradle [--gradle=path/to/gradle/binary] [--out=path/to/result] DIR + Usage + $ socket manifest gradle [--gradle=path/to/gradle/binary] [--out=path/to/result] DIR - Options - --bin Location of gradlew binary to use, default: CWD/gradlew - --cwd Set the cwd, defaults to process.cwd() - --dryRun Do input validation for a command and exit 0 when input is ok - --gradleOpts Additional options to pass on to ./gradlew, see \`./gradlew --help\` - --help Print this help. - --out Path of output file; where to store the resulting manifest, see also --stdout - --stdout Print resulting pom.xml to stdout (supersedes --out) - --task Task to target. By default targets all. - --verbose Print debug messages + Options + --bin Location of gradlew binary to use, default: CWD/gradlew + --cwd Set the cwd, defaults to process.cwd() + --dryRun Do input validation for a command and exit 0 when input is ok + --gradleOpts Additional options to pass on to ./gradlew, see \`./gradlew --help\` + --help Print this help. + --out Path of output file; where to store the resulting manifest, see also --stdout + --stdout Print resulting pom.xml to stdout (supersedes --out) + --task Task to target. By default targets all. + --verbose Print debug messages - Uses gradle, preferably through your local project \`gradlew\`, to generate a - \`pom.xml\` file for each task. If you have no \`gradlew\` you can try the - global \`gradle\` binary but that may not work (hard to predict). + Uses gradle, preferably through your local project \`gradlew\`, to generate a + \`pom.xml\` file for each task. If you have no \`gradlew\` you can try the + global \`gradle\` binary but that may not work (hard to predict). - The \`pom.xml\` is a manifest file similar to \`package.json\` for npm or - or requirements.txt for PyPi), but specifically for Maven, which is Java's - dependency repository. Languages like Kotlin and Scala piggy back on it too. + The \`pom.xml\` is a manifest file similar to \`package.json\` for npm or + or requirements.txt for PyPi), but specifically for Maven, which is Java's + dependency repository. Languages like Kotlin and Scala piggy back on it too. - There are some caveats with the gradle to \`pom.xml\` conversion: + There are some caveats with the gradle to \`pom.xml\` conversion: - - each task will generate its own xml file and by default it generates one xml - for every task. + - each task will generate its own xml file and by default it generates one xml + for every task. - - it's possible certain features don't translate well into the xml. If you - think something is missing that could be supported please reach out. + - it's possible certain features don't translate well into the xml. If you + think something is missing that could be supported please reach out. - - it works with your \`gradlew\` from your repo and local settings and config + - it works with your \`gradlew\` from your repo and local settings and config - Support is beta. Please report issues or give us feedback on what's missing. + Support is beta. Please report issues or give us feedback on what's missing. - Examples + Examples - $ socket manifest gradle . - $ socket manifest gradle --gradlew=../gradlew ." - ` + $ socket manifest gradle . + $ socket manifest gradle --gradlew=../gradlew ." + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest gradle\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest gradle\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket manifest gradle`') + expect(stderr, 'banner includes base command').toContain( + '`socket manifest gradle`' + ) } ) cmdit( - ['manifest', 'gradle', '--dry-run'], + ['manifest', 'gradle', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -101,7 +100,7 @@ describe('socket manifest gradle', async () => { ) cmdit( - ['manifest', 'gradle', 'mootools', '--dry-run'], + ['manifest', 'gradle', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/manifest/cmd-manifest-kotlin.test.ts b/src/commands/manifest/cmd-manifest-kotlin.test.ts index 097e5386e..e686049b8 100644 --- a/src/commands/manifest/cmd-manifest-kotlin.test.ts +++ b/src/commands/manifest/cmd-manifest-kotlin.test.ts @@ -12,72 +12,71 @@ describe('socket manifest kotlin', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['manifest', 'kotlin', '--help'], + ['manifest', 'kotlin', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "[beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Kotlin project + "[beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Kotlin project - Usage - $ socket manifest kotlin [--gradle=path/to/gradle/binary] [--out=path/to/result] DIR + Usage + $ socket manifest kotlin [--gradle=path/to/gradle/binary] [--out=path/to/result] DIR - Options - --bin Location of gradlew binary to use, default: CWD/gradlew - --cwd Set the cwd, defaults to process.cwd() - --dryRun Do input validation for a command and exit 0 when input is ok - --gradleOpts Additional options to pass on to ./gradlew, see \`./gradlew --help\` - --help Print this help. - --out Path of output file; where to store the resulting manifest, see also --stdout - --stdout Print resulting pom.xml to stdout (supersedes --out) - --task Task to target. By default targets all. - --verbose Print debug messages + Options + --bin Location of gradlew binary to use, default: CWD/gradlew + --cwd Set the cwd, defaults to process.cwd() + --dryRun Do input validation for a command and exit 0 when input is ok + --gradleOpts Additional options to pass on to ./gradlew, see \`./gradlew --help\` + --help Print this help. + --out Path of output file; where to store the resulting manifest, see also --stdout + --stdout Print resulting pom.xml to stdout (supersedes --out) + --task Task to target. By default targets all. + --verbose Print debug messages - Uses gradle, preferably through your local project \`gradlew\`, to generate a - \`pom.xml\` file for each task. If you have no \`gradlew\` you can try the - global \`gradle\` binary but that may not work (hard to predict). + Uses gradle, preferably through your local project \`gradlew\`, to generate a + \`pom.xml\` file for each task. If you have no \`gradlew\` you can try the + global \`gradle\` binary but that may not work (hard to predict). - The \`pom.xml\` is a manifest file similar to \`package.json\` for npm or - or requirements.txt for PyPi), but specifically for Maven, which is Java's - dependency repository. Languages like Kotlin and Scala piggy back on it too. + The \`pom.xml\` is a manifest file similar to \`package.json\` for npm or + or requirements.txt for PyPi), but specifically for Maven, which is Java's + dependency repository. Languages like Kotlin and Scala piggy back on it too. - There are some caveats with the gradle to \`pom.xml\` conversion: + There are some caveats with the gradle to \`pom.xml\` conversion: - - each task will generate its own xml file and by default it generates one xml - for every task. (This may be a good thing!) + - each task will generate its own xml file and by default it generates one xml + for every task. (This may be a good thing!) - - it's possible certain features don't translate well into the xml. If you - think something is missing that could be supported please reach out. + - it's possible certain features don't translate well into the xml. If you + think something is missing that could be supported please reach out. - - it works with your \`gradlew\` from your repo and local settings and config + - it works with your \`gradlew\` from your repo and local settings and config - Support is beta. Please report issues or give us feedback on what's missing. + Support is beta. Please report issues or give us feedback on what's missing. - Examples + Examples - $ socket manifest kotlin . - $ socket manifest kotlin --gradlew=../gradlew ." - ` + $ socket manifest kotlin . + $ socket manifest kotlin --gradlew=../gradlew ." + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest kotlin\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest kotlin\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket manifest kotlin`') + expect(stderr, 'banner includes base command').toContain( + '`socket manifest kotlin`' + ) } ) cmdit( - ['manifest', 'kotlin', '--dry-run'], + ['manifest', 'kotlin', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -101,7 +100,7 @@ describe('socket manifest kotlin', async () => { ) cmdit( - ['manifest', 'kotlin', 'mootools', '--dry-run'], + ['manifest', 'kotlin', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/manifest/cmd-manifest-scala.test.ts b/src/commands/manifest/cmd-manifest-scala.test.ts index 1635bf45e..1facfb7d1 100644 --- a/src/commands/manifest/cmd-manifest-scala.test.ts +++ b/src/commands/manifest/cmd-manifest-scala.test.ts @@ -11,10 +11,13 @@ describe('socket manifest scala', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['manifest', 'scala', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['manifest', 'scala', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "[beta] Generate a manifest file (\`pom.xml\`) from Scala's \`build.sbt\` file Usage @@ -60,8 +63,8 @@ describe('socket manifest scala', async () => { $ socket manifest scala ./build.sbt $ socket manifest scala --bin=/usr/bin/sbt ./build.sbt" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -69,14 +72,15 @@ describe('socket manifest scala', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest scala\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket manifest scala`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket manifest scala`' + ) + } + ) cmdit( - ['manifest', 'scala', '--dry-run'], + ['manifest', 'scala', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -100,7 +104,7 @@ describe('socket manifest scala', async () => { ) cmdit( - ['manifest', 'scala', 'mootools', '--dry-run'], + ['manifest', 'scala', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/manifest/cmd-manifest.test.ts b/src/commands/manifest/cmd-manifest.test.ts index fdd87edd5..851c191c7 100644 --- a/src/commands/manifest/cmd-manifest.test.ts +++ b/src/commands/manifest/cmd-manifest.test.ts @@ -11,10 +11,13 @@ describe('socket manifest', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['manifest', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['manifest', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Generate a dependency manifest for given file or dir Usage @@ -33,8 +36,8 @@ describe('socket manifest', async () => { Examples $ socket manifest --help" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -42,14 +45,15 @@ describe('socket manifest', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket manifest`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket manifest`' + ) + } + ) cmdit( - ['manifest', 'mootools', '--dry-run'], + ['manifest', 'mootools', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/npm/cmd-npm.test.ts b/src/commands/npm/cmd-npm.test.ts index bf4c711db..d4f05efbe 100644 --- a/src/commands/npm/cmd-npm.test.ts +++ b/src/commands/npm/cmd-npm.test.ts @@ -11,17 +11,20 @@ describe('socket npm', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['npm', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['npm', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "npm wrapper functionality Usage $ socket npm" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -29,14 +32,13 @@ describe('socket npm', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket npm\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket npm`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket npm`') + } + ) cmdit( - ['npm', '--dry-run'], + ['npm', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/npx/cmd-npx.test.ts b/src/commands/npx/cmd-npx.test.ts index d1765a81a..729d21d96 100644 --- a/src/commands/npx/cmd-npx.test.ts +++ b/src/commands/npx/cmd-npx.test.ts @@ -11,17 +11,20 @@ describe('socket npx', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['npx', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['npx', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "npx wrapper functionality Usage $ socket npx" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -29,14 +32,13 @@ describe('socket npx', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket npx\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket npx`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket npx`') + } + ) cmdit( - ['npx', '--dry-run'], + ['npx', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/oops/cmd-oops.test.ts b/src/commands/oops/cmd-oops.test.ts index 190e02067..b1da36387 100644 --- a/src/commands/oops/cmd-oops.test.ts +++ b/src/commands/oops/cmd-oops.test.ts @@ -11,10 +11,13 @@ describe('socket oops', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['oops', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['oops', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Trigger an intentional error (for development) Usage @@ -22,8 +25,8 @@ describe('socket oops', async () => { Don't run me." ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -31,14 +34,13 @@ describe('socket oops', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket oops\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket oops`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket oops`') + } + ) cmdit( - ['oops', '--dry-run'], + ['oops', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/optimize/cmd-optimize.test.ts b/src/commands/optimize/cmd-optimize.test.ts index d9ee58096..20b646b62 100644 --- a/src/commands/optimize/cmd-optimize.test.ts +++ b/src/commands/optimize/cmd-optimize.test.ts @@ -11,10 +11,13 @@ describe('socket optimize', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['optimize', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['optimize', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Optimize dependencies with @socketregistry overrides Usage @@ -30,8 +33,8 @@ describe('socket optimize', async () => { $ socket optimize $ socket optimize --pin" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,14 +42,15 @@ describe('socket optimize', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket optimize\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket optimize`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket optimize`' + ) + } + ) cmdit( - ['optimize', '--dry-run'], + ['optimize', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/organization/cmd-organization-list.test.ts b/src/commands/organization/cmd-organization-list.test.ts index 314a18f63..e4935185a 100644 --- a/src/commands/organization/cmd-organization-list.test.ts +++ b/src/commands/organization/cmd-organization-list.test.ts @@ -12,53 +12,52 @@ describe('socket organization list', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['organization', 'list', '--help'], + ['organization', 'list', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "List organizations associated with the API key used + "List organizations associated with the API key used - Usage - $ socket organization list + Usage + $ socket organization list - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. - --json Output result as json - --markdown Output result as markdown" - ` + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown" + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization list\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization list\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket organization list`') + expect(stderr, 'banner includes base command').toContain( + '`socket organization list`' + ) } ) cmdit( - ['organization', 'list', '--dry-run'], + ['organization', 'list', '--dry-run', '--config', '{}'], 'should be ok with org name and id', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization list\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization list\`, cwd: " + `) expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) } diff --git a/src/commands/organization/cmd-organization-policy-security.test.ts b/src/commands/organization/cmd-organization-policy-security.test.ts index bc1e78d5b..8ac55e203 100644 --- a/src/commands/organization/cmd-organization-policy-security.test.ts +++ b/src/commands/organization/cmd-organization-policy-security.test.ts @@ -12,49 +12,48 @@ describe('socket organization list', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['organization', 'policy', 'security', '--help'], + ['organization', 'policy', 'security', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "Retrieve the security policy of an organization. + "Retrieve the security policy of an organization. - Usage - $ socket organization policy security + Usage + $ socket organization policy security - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. - --json Output result as json - --markdown Output result as markdown + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown - Your API token will need the \`security-policy:read\` permission otherwise - the request will fail with an authentication error. + Your API token will need the \`security-policy:read\` permission otherwise + the request will fail with an authentication error. - Examples - $ socket organization policy security mycorp - $ socket organization policy security mycorp --json" - ` + Examples + $ socket organization policy security mycorp + $ socket organization policy security mycorp --json" + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket organization policy security`') + expect(stderr, 'banner includes base command').toContain( + '`socket organization policy security`' + ) } ) cmdit( - ['organization', 'policy', 'security', '--dry-run'], + ['organization', 'policy', 'security', '--dry-run', '--config', '{}'], 'should reject dry run without proper args', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -77,18 +76,26 @@ describe('socket organization list', async () => { ) cmdit( - ['organization', 'policy', 'security', 'fakeorg', '--dry-run'], + [ + 'organization', + 'policy', + 'security', + 'fakeorg', + '--dry-run', + '--config', + '{}' + ], 'should be ok with org name and id', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: " + `) expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) } diff --git a/src/commands/organization/cmd-organization-policy.test.ts b/src/commands/organization/cmd-organization-policy.test.ts index 7509e29b3..7285bea20 100644 --- a/src/commands/organization/cmd-organization-policy.test.ts +++ b/src/commands/organization/cmd-organization-policy.test.ts @@ -12,27 +12,27 @@ describe('socket organization list', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['organization', 'policy', '--help'], + ['organization', 'policy', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "Organization policy details + "Organization policy details - Usage - $ socket organization policy + Usage + $ socket organization policy - Commands - + Commands + (none) - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. - Examples - $ socket organization policy --help" - ` + Examples + $ socket organization policy --help" + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` " @@ -43,10 +43,29 @@ describe('socket organization list', async () => { `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket organization policy`') + expect(stderr, 'banner includes base command').toContain( + '`socket organization policy`' + ) + } + ) + + cmdit( + ['organization', 'policy', '--dry-run', '--config', '{}'], + 'should support --dry-run', + 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 + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) } ) }) diff --git a/src/commands/organization/cmd-organization-quota.test.ts b/src/commands/organization/cmd-organization-quota.test.ts index bda3dbdae..900e8e410 100644 --- a/src/commands/organization/cmd-organization-quota.test.ts +++ b/src/commands/organization/cmd-organization-quota.test.ts @@ -12,53 +12,52 @@ describe('socket organization quota', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['organization', 'quota', '--help'], + ['organization', 'quota', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "List organizations associated with the API key used + "List organizations associated with the API key used - Usage - $ socket organization quota + Usage + $ socket organization quota - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. - --json Output result as json - --markdown Output result as markdown" - ` + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown" + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization quota\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization quota\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket organization quota`') + expect(stderr, 'banner includes base command').toContain( + '`socket organization quota`' + ) } ) cmdit( - ['organization', 'quota', '--dry-run'], + ['organization', 'quota', '--dry-run', '--config', '{}'], 'should be ok with org name and id', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket organization quota\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket organization quota\`, cwd: " + `) expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) } diff --git a/src/commands/organization/cmd-organization.test.ts b/src/commands/organization/cmd-organization.test.ts index 039426677..ed8fc6865 100644 --- a/src/commands/organization/cmd-organization.test.ts +++ b/src/commands/organization/cmd-organization.test.ts @@ -11,10 +11,13 @@ describe('socket organization', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['organization', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['organization', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Account details Usage @@ -30,8 +33,8 @@ describe('socket organization', async () => { Examples $ socket organization --help" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,14 +42,15 @@ describe('socket organization', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket organization`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket organization`' + ) + } + ) cmdit( - ['organization', '--dry-run'], + ['organization', '--dry-run', '--config', '{}'], 'should be ok with org name and id', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/package/cmd-package-shallow.test.ts b/src/commands/package/cmd-package-shallow.test.ts index 62eba840b..a0d732229 100644 --- a/src/commands/package/cmd-package-shallow.test.ts +++ b/src/commands/package/cmd-package-shallow.test.ts @@ -12,67 +12,66 @@ describe('socket package shallow', async () => { const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) cmdit( - ['package', 'shallow', '--help'], + ['package', 'shallow', '--help', '--config', '{}'], 'should support --help', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot( ` - "Look up info regarding one or more packages but not their transitives - - Usage - $ socket package shallow < [ ...] | [ ...]> - - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. - --json Output result as json - --markdown Output result as markdown - - Requirements - - quota: 100 - - scope: \`packages:list\` - - Show scoring details for one or more packages purely based on their own package. - This means that any dependency scores are not reflected by the score. You can - use the \`socket package score \` command to get its full transitive score. - - Only a few ecosystems are supported like npm, golang, and maven. - - A "purl" is a standard package name formatting: \`pkg:eco/name@version\` - This command will automatically prepend "pkg:" when not present. - - If the first arg is an ecosystem, remaining args that are not a purl are - assumed to be scoped to that ecosystem. - - Examples - $ socket package shallow npm webtorrent - $ socket package shallow npm webtorrent@1.9.1 - $ socket package shallow npm/webtorrent@1.9.1 - $ socket package shallow pkg:npm/webtorrent@1.9.1 - $ socket package shallow maven webtorrent babel - $ socket package shallow npm/webtorrent golang/babel - $ socket package shallow npm npm/webtorrent@1.0.1 babel" - ` + "Look up info regarding one or more packages but not their transitives + + Usage + $ socket package shallow < [ ...] | [ ...]> + + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown + + Requirements + - quota: 100 + - scope: \`packages:list\` + + Show scoring details for one or more packages purely based on their own package. + This means that any dependency scores are not reflected by the score. You can + use the \`socket package score \` command to get its full transitive score. + + Only a few ecosystems are supported like npm, golang, and maven. + + A "purl" is a standard package name formatting: \`pkg:eco/name@version\` + This command will automatically prepend "pkg:" when not present. + + If the first arg is an ecosystem, remaining args that are not a purl are + assumed to be scoped to that ecosystem. + + Examples + $ socket package shallow npm webtorrent + $ socket package shallow npm webtorrent@1.9.1 + $ socket package shallow npm/webtorrent@1.9.1 + $ socket package shallow pkg:npm/webtorrent@1.9.1 + $ socket package shallow maven webtorrent babel + $ socket package shallow npm/webtorrent golang/babel + $ socket package shallow npm npm/webtorrent@1.0.1 babel" + ` ) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: " + `) expect(code, 'help should exit with code 2').toBe(2) - expect( - stderr, - 'header should include command (without params)' - ).toContain('`socket package shallow`') + expect(stderr, 'banner includes base command').toContain( + '`socket package shallow`' + ) } ) cmdit( - ['package', 'shallow', '--dry-run'], + ['package', 'shallow', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -96,7 +95,7 @@ describe('socket package shallow', async () => { ) cmdit( - ['package', 'shallow', 'npm', 'babel', '--dry-run'], + ['package', 'shallow', 'npm', 'babel', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/package/cmd-package.test.ts b/src/commands/package/cmd-package.test.ts index 90f9a3af0..7df30fb16 100644 --- a/src/commands/package/cmd-package.test.ts +++ b/src/commands/package/cmd-package.test.ts @@ -11,27 +11,30 @@ describe('socket package', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['package', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` - "Commands relating to looking up published packages + 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 + Usage + $ socket package - Commands - + Commands + (none) - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. + 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(` + Examples + $ socket package --help" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,9 +42,30 @@ describe('socket package', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket package`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket package`' + ) + } + ) + + cmdit( + ['package', '--dry-run', '--config', '{}'], + '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 + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) }) diff --git a/src/commands/raw-npm/cmd-raw-npm.test.ts b/src/commands/raw-npm/cmd-raw-npm.test.ts index 006deb92d..80ef71497 100644 --- a/src/commands/raw-npm/cmd-raw-npm.test.ts +++ b/src/commands/raw-npm/cmd-raw-npm.test.ts @@ -11,10 +11,13 @@ describe('socket raw-npm', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['raw-npm', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['raw-npm', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Temporarily disable the Socket npm wrapper Usage @@ -23,8 +26,8 @@ describe('socket raw-npm', async () => { Examples $ socket raw-npm install" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -32,14 +35,15 @@ describe('socket raw-npm', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket raw-npm\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket raw-npm`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket raw-npm`' + ) + } + ) cmdit( - ['raw-npm', '--dry-run'], + ['raw-npm', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/raw-npx/cmd-raw-npx.test.ts b/src/commands/raw-npx/cmd-raw-npx.test.ts index 6963004b6..00f43a044 100644 --- a/src/commands/raw-npx/cmd-raw-npx.test.ts +++ b/src/commands/raw-npx/cmd-raw-npx.test.ts @@ -11,10 +11,13 @@ describe('socket raw-npx', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['raw-npx', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['raw-npx', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Temporarily disable the Socket npx wrapper Usage @@ -23,8 +26,8 @@ describe('socket raw-npx', async () => { Examples $ socket raw-npx install" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -32,14 +35,15 @@ describe('socket raw-npx', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket raw-npx\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket raw-npx`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket raw-npx`' + ) + } + ) cmdit( - ['raw-npx', '--dry-run'], + ['raw-npx', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/report/cmd-report-create.test.ts b/src/commands/report/cmd-report-create.test.ts index 5e5a45036..0626ee577 100644 --- a/src/commands/report/cmd-report-create.test.ts +++ b/src/commands/report/cmd-report-create.test.ts @@ -11,17 +11,20 @@ describe('socket report create', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['report', 'create', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['report', 'create', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "[Deprecated] Create a project report This command is deprecated in favor of \`socket scan view\`. It will be removed in the next major release of the CLI." ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -29,14 +32,15 @@ describe('socket report create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket report create`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket report create`' + ) + } + ) cmdit( - ['report', 'create', '--dry-run'], + ['report', 'create', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/report/cmd-report-view.test.ts b/src/commands/report/cmd-report-view.test.ts index 5e5a45036..0626ee577 100644 --- a/src/commands/report/cmd-report-view.test.ts +++ b/src/commands/report/cmd-report-view.test.ts @@ -11,17 +11,20 @@ describe('socket report create', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['report', 'create', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['report', 'create', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "[Deprecated] Create a project report This command is deprecated in favor of \`socket scan view\`. It will be removed in the next major release of the CLI." ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -29,14 +32,15 @@ describe('socket report create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket report create`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket report create`' + ) + } + ) cmdit( - ['report', 'create', '--dry-run'], + ['report', 'create', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/report/cmd-report.test.ts b/src/commands/report/cmd-report.test.ts index a1dd53239..cf9617ef1 100644 --- a/src/commands/report/cmd-report.test.ts +++ b/src/commands/report/cmd-report.test.ts @@ -11,10 +11,13 @@ describe('socket report', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['report', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['report', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "[Deprecated] Project report related commands Usage @@ -31,8 +34,8 @@ describe('socket report', async () => { Examples $ socket report --help" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -40,14 +43,15 @@ describe('socket report', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket report`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket report`' + ) + } + ) cmdit( - ['report', '--dry-run'], + ['report', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/repos/cmd-repos-create.test.ts b/src/commands/repos/cmd-repos-create.test.ts new file mode 100644 index 000000000..ab5833d01 --- /dev/null +++ b/src/commands/repos/cmd-repos-create.test.ts @@ -0,0 +1,95 @@ +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 repos create', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', 'create', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "Create a repository in an organization + + Usage + $ socket repos create + + Options + --defaultBranch Repository default branch + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --homepage Repository url + --repoDescription Repository description + --repoName Repository name + --visibility Repository visibility (Default Private) + + Examples + $ socket repos create FakeOrg --repoName=test-repo" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos create\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket repos create`' + ) + } + ) + + cmdit( + ['repos', 'create', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`""`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos create\`, cwd: + + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: + + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m + + - Repository name using --repoName \\x1b[31m(missing!)\\x1b[39m" + `) + + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) + } + ) + + cmdit( + ['repos', 'create', 'a', '--repoName', 'b', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos create\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/repos/cmd-repos-del.test.ts b/src/commands/repos/cmd-repos-del.test.ts new file mode 100644 index 000000000..e2b6fbbdc --- /dev/null +++ b/src/commands/repos/cmd-repos-del.test.ts @@ -0,0 +1,92 @@ +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 repos del', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', 'del', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "Delete a repository in an organization + + Usage + $ socket repos del + + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + + Examples + $ socket repos del FakeOrg test-repo" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos del\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket repos del`' + ) + } + ) + + cmdit( + ['repos', 'del', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`""`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos del\`, cwd: + + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: + + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m + + - Repository name as the second argument \\x1b[31m(missing!)\\x1b[39m + + - At least one TARGET (e.g. \`.\` or \`./package.json\`" + `) + + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) + } + ) + + cmdit( + ['repos', 'del', 'a', 'b', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos del\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/repos/cmd-repos-list.test.ts b/src/commands/repos/cmd-repos-list.test.ts new file mode 100644 index 000000000..b662bcecf --- /dev/null +++ b/src/commands/repos/cmd-repos-list.test.ts @@ -0,0 +1,96 @@ +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 repos list', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', 'list', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "List repositories in an organization + + Usage + $ socket repos list + + Options + --direction Direction option + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown + --page Page number + --perPage Number of results per page + --sort Sorting option + + Examples + $ socket repos list FakeOrg" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos list\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket repos list`' + ) + } + ) + + cmdit( + ['repos', 'list', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`""`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos list\`, cwd: + + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: + + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m + + - At least one TARGET (e.g. \`.\` or \`./package.json\`" + `) + + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) + } + ) + + cmdit( + ['repos', 'list', 'a', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos list\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/repos/cmd-repos-update.test.ts b/src/commands/repos/cmd-repos-update.test.ts new file mode 100644 index 000000000..bd6b8d087 --- /dev/null +++ b/src/commands/repos/cmd-repos-update.test.ts @@ -0,0 +1,97 @@ +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 repos update', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', 'update', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "Update a repository in an organization + + Usage + $ socket repos update + + Options + --defaultBranch Repository default branch + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --homepage Repository url + --repoDescription Repository description + --repoName Repository name + --visibility Repository visibility (Default Private) + + Examples + $ socket repos update FakeOrg" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos update\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket repos update`' + ) + } + ) + + cmdit( + ['repos', 'update', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`""`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos update\`, cwd: + + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: + + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m + + - Repository name using --repoName \\x1b[31m(missing!)\\x1b[39m + + - At least one TARGET (e.g. \`.\` or \`./package.json\`" + `) + + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) + } + ) + + cmdit( + ['repos', 'update', 'a', '--repoName', 'b', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos update\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/repos/cmd-repos-view.test.ts b/src/commands/repos/cmd-repos-view.test.ts new file mode 100644 index 000000000..b669914cc --- /dev/null +++ b/src/commands/repos/cmd-repos-view.test.ts @@ -0,0 +1,93 @@ +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 repos view', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', 'view', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "View repositories in an organization + + Usage + $ socket repos view + + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + --json Output result as json + --markdown Output result as markdown + --repoName The repository to check + + Examples + $ socket repos view FakeOrg" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos view\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket repos view`' + ) + } + ) + + cmdit( + ['repos', 'view', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`""`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos view\`, cwd: + + \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields: + + - Org name as the first argument \\x1b[31m(missing!)\\x1b[39m + + - Repository name using --repoName \\x1b[31m(missing!)\\x1b[39m" + `) + + expect(code, 'dry-run should exit with code 2 if missing input').toBe(2) + } + ) + + cmdit( + ['repos', 'view', 'a', '--repoName', 'b', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos view\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/repos/cmd-repos.test.ts b/src/commands/repos/cmd-repos.test.ts new file mode 100644 index 000000000..515174f6a --- /dev/null +++ b/src/commands/repos/cmd-repos.test.ts @@ -0,0 +1,73 @@ +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 repos', async () => { + // Lazily access constants.rootBinPath. + const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) + + cmdit( + ['repos', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "Repositories related commands + + Usage + $ socket repos + + Commands + create Create a repository in an organization + del Delete a repository in an organization + list List repositories in an organization + update Update a repository in an organization + view View repositories in an organization + + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. + + Examples + $ socket repos --help" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos\`, cwd: " + `) + + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket repos`') + } + ) + + cmdit( + ['repos', '--dry-run', '--config', '{}'], + 'should require args with just dry-run', + 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 + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket repos\`, cwd: " + `) + + expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) + } + ) +}) diff --git a/src/commands/scan/cmd-scan-create.test.ts b/src/commands/scan/cmd-scan-create.test.ts index dceebd90a..2c821cde0 100644 --- a/src/commands/scan/cmd-scan-create.test.ts +++ b/src/commands/scan/cmd-scan-create.test.ts @@ -11,25 +11,64 @@ describe('socket scan create', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'create', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot(`""`) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + cmdit( + ['scan', 'create', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot(` + "Create a scan + + Usage + $ socket scan create [...options] [TARGET...] + + Uploads the specified "package.json" and lock files for JavaScript, Python, + Go, Scala, Gradle, and Kotlin dependency manifests. + If any folder is specified, the ones found in there recursively are uploaded. + + Supports globbing such as "**/package.json", "**/requirements.txt", etc. + + Ignores any file specified in your project's ".gitignore" and also has a + sensible set of default ignores from the "ignore-by-default" module. + + TARGET should be a FILE or DIR that _must_ be inside the CWD. + + When a FILE is given only that FILE is targeted. Otherwise any eligible + files in the given DIR will be considered. + + Options + --branch Branch name + --commitHash Commit hash + --commitMessage Commit message + --committers Committers + --cwd working directory, defaults to process.cwd() + --defaultBranch Make default branch + --dryRun run input validation part of command without any concrete side effects + --help Print this help. + --pendingHead Set as pending head + --pullRequest Commit hash + --readOnly Similar to --dry-run except it can read from remote, stops before it would create an actual report + --repo Repository name + --tmp Set the visibility (true/false) of the scan in your dashboard + --view Will wait for and return the created report. Use --no-view to disable. + + Examples + $ socket scan create --repo=test-repo --branch=main FakeOrg ./package.json" + `) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket scan create\`, cwd: - - Unknown flag - --help" + |_____|___|___|_,_|___|_|.dev | Command: \`socket scan create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan create`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan create`' + ) + } + ) cmdit( [ diff --git a/src/commands/scan/cmd-scan-create.ts b/src/commands/scan/cmd-scan-create.ts index 64d27dabc..6b74af50a 100644 --- a/src/commands/scan/cmd-scan-create.ts +++ b/src/commands/scan/cmd-scan-create.ts @@ -11,6 +11,7 @@ import { suggestRepoSlug } from './suggest-repo-slug' import { suggestBranchSlug } from './suggest_branch_slug' import { suggestTarget } from './suggest_target' import constants from '../../constants' +import { commonFlags } from '../../flags' import { meowOrExit } from '../../utils/meow-with-subcommands' import { getFlagListOutput } from '../../utils/output-formatting' import { getDefaultToken } from '../../utils/sdk' @@ -24,6 +25,7 @@ const config: CliCommandConfig = { description: 'Create a scan', hidden: false, flags: { + ...commonFlags, repo: { type: 'string', shortFlag: 'r', diff --git a/src/commands/scan/cmd-scan-del.test.ts b/src/commands/scan/cmd-scan-del.test.ts index 155304a3f..1ae755342 100644 --- a/src/commands/scan/cmd-scan-del.test.ts +++ b/src/commands/scan/cmd-scan-del.test.ts @@ -11,10 +11,13 @@ describe('socket scan del', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'del', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['scan', 'del', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Delete a scan Usage @@ -29,8 +32,8 @@ describe('socket scan del', async () => { Examples $ socket scan del FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -38,14 +41,15 @@ describe('socket scan del', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan del\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan del`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan del`' + ) + } + ) cmdit( - ['scan', 'del', '--dry-run'], + ['scan', 'del', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -69,7 +73,7 @@ describe('socket scan del', async () => { ) cmdit( - ['scan', 'del', 'fakeorg', 'scanidee', '--dry-run'], + ['scan', 'del', 'fakeorg', 'scanidee', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/scan/cmd-scan-list.test.ts b/src/commands/scan/cmd-scan-list.test.ts index b780f6c74..183769495 100644 --- a/src/commands/scan/cmd-scan-list.test.ts +++ b/src/commands/scan/cmd-scan-list.test.ts @@ -11,10 +11,13 @@ describe('socket scan list', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'list', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['scan', 'list', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "List the scans for an organization Usage @@ -35,8 +38,8 @@ describe('socket scan list', async () => { Examples $ socket scan list FakeOrg" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -44,14 +47,15 @@ describe('socket scan list', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan list`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan list`' + ) + } + ) cmdit( - ['scan', 'list', '--dry-run'], + ['scan', 'list', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -73,7 +77,7 @@ describe('socket scan list', async () => { ) cmdit( - ['scan', 'list', 'fakeorg', '--dry-run'], + ['scan', 'list', 'fakeorg', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/scan/cmd-scan-metadata.test.ts b/src/commands/scan/cmd-scan-metadata.test.ts index e5028e524..34fd793f5 100644 --- a/src/commands/scan/cmd-scan-metadata.test.ts +++ b/src/commands/scan/cmd-scan-metadata.test.ts @@ -11,10 +11,13 @@ describe('socket scan metadata', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'metadata', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['scan', 'metadata', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Get a scan's metadata Usage @@ -29,8 +32,8 @@ describe('socket scan metadata', async () => { Examples $ socket scan metadata FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -38,14 +41,15 @@ describe('socket scan metadata', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan metadata\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan metadata`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan metadata`' + ) + } + ) cmdit( - ['scan', 'metadata', '--dry-run'], + ['scan', 'metadata', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -69,7 +73,7 @@ describe('socket scan metadata', async () => { ) cmdit( - ['scan', 'metadata', 'fakeorg', 'scanidee', '--dry-run'], + ['scan', 'metadata', 'fakeorg', 'scanidee', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/scan/cmd-scan-report.test.ts b/src/commands/scan/cmd-scan-report.test.ts index eaa080ad0..1f3755232 100644 --- a/src/commands/scan/cmd-scan-report.test.ts +++ b/src/commands/scan/cmd-scan-report.test.ts @@ -11,10 +11,13 @@ describe('socket scan report', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'report', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['scan', 'report', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Check whether a scan result passes the organizational policies (security, license) Usage @@ -49,8 +52,8 @@ describe('socket scan report', async () => { Examples $ socket scan report FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 --json --fold=version" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -58,14 +61,15 @@ describe('socket scan report', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan report\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan report`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan report`' + ) + } + ) cmdit( - ['scan', 'report', '--dry-run'], + ['scan', 'report', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -91,18 +95,18 @@ describe('socket scan report', async () => { ) cmdit( - ['scan', 'report', 'org', 'report-id', '--dry-run'], + ['scan', 'report', 'org', 'report-id', '--dry-run', '--config', '{}'], 'should be ok with org name and id', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) expect(stdout).toMatchInlineSnapshot(`"[DryRun]: Bailing now"`) expect(`\n ${stderr}`).toMatchInlineSnapshot(` - " - _____ _ _ /--------------- - | __|___ ___| |_ ___| |_ | Socket.dev CLI ver - |__ | . | _| '_| -_| _| | Node: , API token set: - |_____|___|___|_,_|___|_|.dev | Command: \`socket scan report\`, cwd: " - `) + " + _____ _ _ /--------------- + | __|___ ___| |_ ___| |_ | Socket.dev CLI ver + |__ | . | _| '_| -_| _| | Node: , API token set: + |_____|___|___|_,_|___|_|.dev | Command: \`socket scan report\`, cwd: " + `) expect(code, 'dry-run should exit with code 0 if input ok').toBe(0) } diff --git a/src/commands/scan/cmd-scan-view.test.ts b/src/commands/scan/cmd-scan-view.test.ts index ac23935e7..eafbd14a1 100644 --- a/src/commands/scan/cmd-scan-view.test.ts +++ b/src/commands/scan/cmd-scan-view.test.ts @@ -11,10 +11,13 @@ describe('socket scan view', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', 'view', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['scan', 'view', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "View the raw results of a scan Usage @@ -31,8 +34,8 @@ describe('socket scan view', async () => { Examples $ socket scan view FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -40,14 +43,15 @@ describe('socket scan view', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan view\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan view`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket scan view`' + ) + } + ) cmdit( - ['scan', 'view', '--dry-run'], + ['scan', 'view', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) @@ -71,7 +75,7 @@ describe('socket scan view', async () => { ) cmdit( - ['scan', 'view', 'fakeorg', 'scanidee', '--dry-run'], + ['scan', 'view', 'fakeorg', 'scanidee', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/scan/cmd-scan.test.ts b/src/commands/scan/cmd-scan.test.ts index b15500872..62c8f3979 100644 --- a/src/commands/scan/cmd-scan.test.ts +++ b/src/commands/scan/cmd-scan.test.ts @@ -11,31 +11,34 @@ describe('socket scan', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['scan', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` - "Full Scan related commands + cmdit( + ['scan', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` + "Full Scan related commands - Usage - $ socket scan + Usage + $ socket scan - Commands - create Create a scan - del Delete a scan - list List the scans for an organization - metadata Get a scan's metadata - view View the raw results of a scan + Commands + create Create a scan + del Delete a scan + list List the scans for an organization + metadata Get a scan's metadata + view View the raw results of a scan - Options - --dryRun Do input validation for a command and exit 0 when input is ok - --help Print this help. + Options + --dryRun Do input validation for a command and exit 0 when input is ok + --help Print this help. - Examples - $ socket scan --help" - ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + Examples + $ socket scan --help" + ` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -43,14 +46,13 @@ describe('socket scan', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket scan`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain('`socket scan`') + } + ) cmdit( - ['scan', '--dry-run'], + ['scan', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/threat-feed/cmd-threat-feed.test.ts b/src/commands/threat-feed/cmd-threat-feed.test.ts index bc226e8d9..244e36fdb 100644 --- a/src/commands/threat-feed/cmd-threat-feed.test.ts +++ b/src/commands/threat-feed/cmd-threat-feed.test.ts @@ -11,10 +11,13 @@ describe('socket threat-feed', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['threat-feed', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['threat-feed', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "[beta] View the threat feed Usage @@ -61,8 +64,8 @@ describe('socket threat-feed', async () => { $ socket threat-feed $ socket threat-feed --perPage=5 --page=2 --direction=asc --filter=joke" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -70,14 +73,15 @@ describe('socket threat-feed', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket threat-feed\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket threat-feed`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket threat-feed`' + ) + } + ) cmdit( - ['threat-feed', '--dry-run'], + ['threat-feed', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/commands/wrapper/cmd-wrapper.test.ts b/src/commands/wrapper/cmd-wrapper.test.ts index f36b24cec..d8c82ae5a 100644 --- a/src/commands/wrapper/cmd-wrapper.test.ts +++ b/src/commands/wrapper/cmd-wrapper.test.ts @@ -11,10 +11,13 @@ describe('socket wrapper', async () => { // Lazily access constants.rootBinPath. const entryPath = path.join(constants.rootBinPath, `${CLI}.js`) - cmdit(['wrapper', '--help'], 'should support --help', async cmd => { - const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) - expect(stdout).toMatchInlineSnapshot( - ` + cmdit( + ['wrapper', '--help', '--config', '{}'], + 'should support --help', + async cmd => { + const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) + expect(stdout).toMatchInlineSnapshot( + ` "Enable or disable the Socket npm/npx wrapper Usage @@ -30,8 +33,8 @@ describe('socket wrapper', async () => { $ socket wrapper --enable $ socket wrapper --disable" ` - ) - expect(`\n ${stderr}`).toMatchInlineSnapshot(` + ) + expect(`\n ${stderr}`).toMatchInlineSnapshot(` " _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver @@ -39,14 +42,15 @@ describe('socket wrapper', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket wrapper\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) - expect(stderr, 'header should include command (without params)').toContain( - '`socket wrapper`' - ) - }) + expect(code, 'help should exit with code 2').toBe(2) + expect(stderr, 'banner includes base command').toContain( + '`socket wrapper`' + ) + } + ) cmdit( - ['wrapper', '--dry-run'], + ['wrapper', '--dry-run', '--config', '{}'], 'should require args with just dry-run', async cmd => { const { code, stderr, stdout } = await invokeNpm(entryPath, cmd) diff --git a/src/flags.ts b/src/flags.ts index 33e3be831..1b1ba8aee 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -7,9 +7,18 @@ type NumberFlag = Flag<'number', number> | Flag<'number', number[], true> type AnyFlag = StringFlag | BooleanFlag | NumberFlag // Note: we use this description in getFlagListOutput, meow doesn't care -export type MeowFlags = Record +export type MeowFlags = Record< + string, + AnyFlag & { description: string; hidden?: boolean } +> export const commonFlags: MeowFlags = { + config: { + type: 'string', + default: '', + hidden: true, + description: 'Override the local config with this JSON' + }, help: { type: 'boolean', default: false, diff --git a/src/utils/config.ts b/src/utils/config.ts index e5a67e66e..ee130f32f 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -41,13 +41,21 @@ export const supportedConfigKeys: Map = new Map([ export const sensitiveConfigKeys: Set = new Set(['apiToken']) let cachedConfig: LocalConfig | undefined +// When using --config or SOCKET_CLI_CONFIG_OVERRIDE, do not persist the config +let readOnlyConfig = false let configPath: string | undefined let warnedConfigPathWin32Missing = false let pendingSave = false +export function overrideCachedConfig(config: unknown) { + cachedConfig = config as LocalConfig + readOnlyConfig = true +} + function getConfigValues(): LocalConfig { if (cachedConfig === undefined) { cachedConfig = {} as LocalConfig + // Order: env var > --config flag > file const configPath = getConfigPath() if (configPath) { const raw = safeReadFileSync(configPath) @@ -157,7 +165,11 @@ export function updateConfigValue( ): void { const localConfig = getConfigValues() localConfig[normalizeConfigKey(key) as Key] = value - if (!pendingSave) { + if (readOnlyConfig) { + logger.error( + 'Not persisting config change; current config overridden through env var or flag' + ) + } else if (!pendingSave) { pendingSave = true process.nextTick(() => { pendingSave = false diff --git a/src/utils/meow-with-subcommands.ts b/src/utils/meow-with-subcommands.ts index e208196b9..0b5ef4fad 100644 --- a/src/utils/meow-with-subcommands.ts +++ b/src/utils/meow-with-subcommands.ts @@ -1,4 +1,5 @@ import path from 'node:path' +import process from 'node:process' import meow from 'meow' @@ -8,7 +9,7 @@ import { normalizePath } from '@socketsecurity/registry/lib/path' import { escapeRegExp } from '@socketsecurity/registry/lib/regexps' import { getLastFiveOfApiToken } from './api' -import { getConfigValue } from './config' +import { getConfigValue, overrideCachedConfig } from './config' import { getFlagListOutput, getHelpListOutput } from './output-formatting' import constants from '../constants' import { MeowFlags, commonFlags } from '../flags' @@ -81,29 +82,11 @@ export async function meowWithSubcommands( if (!commandOrAliasName && defaultSub) { commandOrAliasName = defaultSub } - // If we got at least some args, then lets find out if we can find a command. - if (commandOrAliasName) { - const alias = aliases[commandOrAliasName] - // First: Resolve argv data from alias if its an alias that's been given. - const [commandName, ...commandArgv] = alias - ? [...alias.argv, ...rawCommandArgv] - : [commandOrAliasName, ...rawCommandArgv] - // Second: Find a command definition using that data. - const commandDefinition = commandName ? subcommands[commandName] : undefined - // Third: If a valid command has been found, then we run it... - if (commandDefinition) { - return await commandDefinition.run(commandArgv, importMeta, { - parentName: name - }) - } - } - const flags = { + + const flags: MeowFlags = { ...commonFlags, ...additionalOptions.flags } - // ...else we provide basic instructions and help. - - emitBanner(name) const cli = meow( ` @@ -145,9 +128,44 @@ export async function meowWithSubcommands( importMeta, ...additionalOptions, flags, - autoHelp: false // otherwise we can't exit(0) + // Do not strictly check for flags here. + allowUnknownFlags: true, + // We will emit help when we're ready + // Plus, if we allow this then meow() can just exit here. + autoHelp: false } ) + + // Hard override the config if instructed to do so. + // The env var overrides the --flag, which overrides the persisted config + // Also, when either of these are used, config updates won't persist. + if (process.env['SOCKET_CLI_CONFIG']) { + overrideCachedConfig(JSON.parse(process.env['SOCKET_CLI_CONFIG'])) + } else if (cli.flags['config']) { + overrideCachedConfig(JSON.parse(String(cli.flags['config'] || ''))) + } + + // If we got at least some args, then lets find out if we can find a command. + if (commandOrAliasName) { + const alias = aliases[commandOrAliasName] + // First: Resolve argv data from alias if its an alias that's been given. + const [commandName, ...commandArgv] = alias + ? [...alias.argv, ...rawCommandArgv] + : [commandOrAliasName, ...rawCommandArgv] + // Second: Find a command definition using that data. + const commandDefinition = commandName ? subcommands[commandName] : undefined + // Third: If a valid command has been found, then we run it... + if (commandDefinition) { + return await commandDefinition.run(commandArgv, importMeta, { + parentName: name + }) + } + } + + // ...else we provide basic instructions and help. + + emitBanner(name) + if (!cli.flags['help'] && cli.flags['dryRun']) { process.exitCode = 0 logger.log(`${DRY_RUN_LABEL}: No-op, call a sub-command; ok`) diff --git a/src/utils/output-formatting.ts b/src/utils/output-formatting.ts index 488658da7..659242c36 100644 --- a/src/utils/output-formatting.ts +++ b/src/utils/output-formatting.ts @@ -1,12 +1,16 @@ +import type { MeowFlags } from '../flags' + type HelpListOptions = { keyPrefix: string padName: number } -type ListDescription = string | { description: string } +type ListDescription = + | { description: string } + | { description: string; hidden: boolean } export function getFlagListOutput( - list: Record, + list: MeowFlags, indent: number, { keyPrefix = '--', padName } = {} as HelpListOptions ): string { @@ -27,16 +31,17 @@ export function getHelpListOutput( let result = '' const names = Object.keys(list).sort() for (const name of names) { - const rawDescription = list[name] + const entry = list[name] + if (entry && 'hidden' in entry && entry?.hidden) { + continue + } const description = - (typeof rawDescription === 'object' - ? rawDescription.description - : rawDescription) || '' + (typeof entry === 'object' ? entry.description : entry) || '' result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n' } - return result.trim() + return result.trim() || '(none)' } From 4230190319674d28628433ce31eccf57bc6a7f14 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 25 Mar 2025 15:16:16 +0100 Subject: [PATCH 2/2] Do not import process. --- src/commands/cdxgen/cmd-cdxgen.ts | 2 -- src/commands/optimize/cmd-optimize.ts | 2 -- src/commands/report/cmd-report-create.ts | 1 - src/commands/scan/cmd-scan-create.ts | 2 -- 4 files changed, 7 deletions(-) diff --git a/src/commands/cdxgen/cmd-cdxgen.ts b/src/commands/cdxgen/cmd-cdxgen.ts index 08066cf57..97eaa6ef3 100644 --- a/src/commands/cdxgen/cmd-cdxgen.ts +++ b/src/commands/cdxgen/cmd-cdxgen.ts @@ -1,6 +1,4 @@ // import { meowOrExit } from '../../utils/meow-with-subcommands' -import process from 'node:process' - import yargsParse from 'yargs-parser' import { logger } from '@socketsecurity/registry/lib/logger' diff --git a/src/commands/optimize/cmd-optimize.ts b/src/commands/optimize/cmd-optimize.ts index 636ba8780..e9243678e 100644 --- a/src/commands/optimize/cmd-optimize.ts +++ b/src/commands/optimize/cmd-optimize.ts @@ -1,5 +1,3 @@ -import process from 'node:process' - import { logger } from '@socketsecurity/registry/lib/logger' import { applyOptimization } from './apply-optimization' diff --git a/src/commands/report/cmd-report-create.ts b/src/commands/report/cmd-report-create.ts index 25c7e4d2d..7fad642b1 100644 --- a/src/commands/report/cmd-report-create.ts +++ b/src/commands/report/cmd-report-create.ts @@ -1,5 +1,4 @@ import path from 'node:path' -import process from 'node:process' import { logger } from '@socketsecurity/registry/lib/logger' diff --git a/src/commands/scan/cmd-scan-create.ts b/src/commands/scan/cmd-scan-create.ts index 6b74af50a..38d44c9ab 100644 --- a/src/commands/scan/cmd-scan-create.ts +++ b/src/commands/scan/cmd-scan-create.ts @@ -1,5 +1,3 @@ -import process from 'node:process' - import { stripIndents } from 'common-tags' import colors from 'yoctocolors-cjs'