From 899e142a3f091c8347d861ea9c45f0c94231bd24 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Fri, 14 Mar 2025 14:14:57 +0100 Subject: [PATCH] Create test file for each command, move dryrun tests there --- package.json | 1 + src/commands/analytics/cmd-analytics.test.ts | 73 ++ src/commands/audit-log/cmd-audit-log.test.ts | 92 ++ src/commands/cdxgen/cmd-cdxgen.test.ts | 109 +++ .../dependencies/cmd-dependencies.test.ts | 66 ++ .../diff-scan/cmd-diff-scan-get.test.ts | 107 +++ src/commands/diff-scan/cmd-diff-scan.test.ts | 67 ++ src/commands/fix/cmd-fix.test.ts | 59 ++ src/commands/info/cmd-info.test.ts | 91 ++ src/commands/login/cmd-login.test.ts | 67 ++ src/commands/logout/cmd-logout.test.ts | 57 ++ .../manifest/cmd-manifest-auto.test.ts | 65 ++ src/commands/manifest/cmd-manifest-auto.ts | 5 + .../manifest/cmd-manifest-gradle.test.ts | 120 +++ .../manifest/cmd-manifest-kotlin.test.ts | 120 +++ .../manifest/cmd-manifest-scala.test.ts | 119 +++ src/commands/manifest/cmd-manifest.test.ts | 70 ++ src/commands/npm/cmd-npm.test.ts | 55 ++ src/commands/npx/cmd-npx.test.ts | 55 ++ src/commands/oops/cmd-oops.test.ts | 57 ++ src/commands/optimize/cmd-optimize.test.ts | 65 ++ src/commands/raw-npm/cmd-raw-npm.test.ts | 58 ++ src/commands/raw-npx/cmd-raw-npx.test.ts | 58 ++ src/commands/report/cmd-report-create.test.ts | 55 ++ src/commands/report/cmd-report-create.ts | 2 +- src/commands/report/cmd-report-view.test.ts | 55 ++ src/commands/report/cmd-report.test.ts | 68 ++ src/commands/scan/cmd-scan-create.test.ts | 61 ++ src/commands/scan/cmd-scan-del.test.ts | 88 ++ src/commands/scan/cmd-scan-list.test.ts | 92 ++ src/commands/scan/cmd-scan-list.ts | 2 +- src/commands/scan/cmd-scan-metadata.test.ts | 88 ++ src/commands/scan/cmd-scan-metadata.ts | 2 +- src/commands/scan/cmd-scan-view.test.ts | 90 ++ src/commands/scan/cmd-scan.test.ts | 71 ++ .../threat-feed/cmd-threat-feed.test.ts | 96 ++ src/commands/wrapper/cmd-wrapper.test.ts | 87 ++ test/dry-run.test.ts | 833 ------------------ 38 files changed, 2490 insertions(+), 836 deletions(-) create mode 100644 src/commands/analytics/cmd-analytics.test.ts create mode 100644 src/commands/audit-log/cmd-audit-log.test.ts create mode 100644 src/commands/cdxgen/cmd-cdxgen.test.ts create mode 100644 src/commands/dependencies/cmd-dependencies.test.ts create mode 100644 src/commands/diff-scan/cmd-diff-scan-get.test.ts create mode 100644 src/commands/diff-scan/cmd-diff-scan.test.ts create mode 100644 src/commands/fix/cmd-fix.test.ts create mode 100644 src/commands/info/cmd-info.test.ts create mode 100644 src/commands/login/cmd-login.test.ts create mode 100644 src/commands/logout/cmd-logout.test.ts create mode 100644 src/commands/manifest/cmd-manifest-auto.test.ts create mode 100644 src/commands/manifest/cmd-manifest-gradle.test.ts create mode 100644 src/commands/manifest/cmd-manifest-kotlin.test.ts create mode 100644 src/commands/manifest/cmd-manifest-scala.test.ts create mode 100644 src/commands/manifest/cmd-manifest.test.ts create mode 100644 src/commands/npm/cmd-npm.test.ts create mode 100644 src/commands/npx/cmd-npx.test.ts create mode 100644 src/commands/oops/cmd-oops.test.ts create mode 100644 src/commands/optimize/cmd-optimize.test.ts create mode 100644 src/commands/raw-npm/cmd-raw-npm.test.ts create mode 100644 src/commands/raw-npx/cmd-raw-npx.test.ts create mode 100644 src/commands/report/cmd-report-create.test.ts create mode 100644 src/commands/report/cmd-report-view.test.ts create mode 100644 src/commands/report/cmd-report.test.ts create mode 100644 src/commands/scan/cmd-scan-create.test.ts create mode 100644 src/commands/scan/cmd-scan-del.test.ts create mode 100644 src/commands/scan/cmd-scan-list.test.ts create mode 100644 src/commands/scan/cmd-scan-metadata.test.ts create mode 100644 src/commands/scan/cmd-scan-view.test.ts create mode 100644 src/commands/scan/cmd-scan.test.ts create mode 100644 src/commands/threat-feed/cmd-threat-feed.test.ts create mode 100644 src/commands/wrapper/cmd-wrapper.test.ts delete mode 100644 test/dry-run.test.ts diff --git a/package.json b/package.json index eaa805956..a5573c8dd 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "test:unit:coverage": "vitest run --coverage", "test-ci": "run-s test:*", "testu": "cross-env SOCKET_CLI_NO_API_TOKEN=1 run-s test:prepare; npm run test:unit:update --", + "testuf": "SOCKET_CLI_NO_API_TOKEN=1 npm run test:unit:update --", "update": "run-p --aggregate-output update:**", "update:deps": "npx --yes npm-check-updates" }, diff --git a/src/commands/analytics/cmd-analytics.test.ts b/src/commands/analytics/cmd-analytics.test.ts new file mode 100644 index 000000000..76f962436 --- /dev/null +++ b/src/commands/analytics/cmd-analytics.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 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( + ` + "Look up analytics data + + Usage + $ socket analytics --scope= --time=