Skip to content

test(cli): add unit tests for dlx, sea, and constants #955

test(cli): add unit tests for dlx, sea, and constants

test(cli): add unit tests for dlx, sea, and constants #955

Workflow file for this run

name: 🚀 CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
on:
push:
branches: [main]
tags: ['*']
paths:
- 'packages/cli/**'
- 'pnpm-lock.yaml'
- 'package.json'
- '.github/workflows/ci.yml'
pull_request:
branches: [main]
paths:
- 'packages/cli/**'
- 'pnpm-lock.yaml'
- 'package.json'
- '.github/workflows/ci.yml'
workflow_dispatch:
inputs:
force:
description: 'Force rebuild (ignore cache)'
type: boolean
default: false
node-versions:
description: 'Node.js versions to test (JSON array)'
required: false
type: string
# Default should match .node-version file.
default: '["25"]'
permissions: {}
env:
# Opt-in to Node.js 24 for GitHub Actions to avoid deprecation warnings.
# See: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
versions:
name: Load Tool Versions
runs-on: ubuntu-latest
permissions:
contents: read # Read .node-version file from repository.
outputs:
node: ${{ steps.versions.outputs.node }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Load Node.js version from .node-version
id: versions
run: |
NODE_VERSION=$(cat .node-version)
echo "node=[\"$NODE_VERSION\"]" >> $GITHUB_OUTPUT
echo "Loaded Node.js: $NODE_VERSION"
# Lint and type check jobs (run in parallel).
lint:
name: 🧹 Lint Check
needs: versions
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: .node-version
- name: Setup pnpm
uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run lint
run: pnpm --filter @socketsecurity/cli run check
type-check:
name: 🔍 Type Check
needs: versions
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: .node-version
- name: Setup pnpm
uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run type check
run: pnpm --filter @socketsecurity/cli run type
# Sharded unit tests for faster CI.
test-sharded:
name: Unit Tests (Shard ${{ matrix.shard }}/3)
needs: [lint, type-check, versions]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
strategy:
fail-fast: false
max-parallel: 4
matrix:
node-version: ${{ fromJSON(inputs.node-versions || needs.versions.outputs.node) }}
shard: [1, 2, 3]
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build CLI
working-directory: packages/cli
run: pnpm run build
- name: Run unit tests (shard ${{ matrix.shard }})
working-directory: packages/cli
run: pnpm test:unit --shard=${{ matrix.shard }}/3
# E2E tests
e2e:
name: E2E Tests (Shard ${{ matrix.shard }}/2)
needs: [lint, type-check, versions]
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
strategy:
fail-fast: false
max-parallel: 4
matrix:
node-version: ${{ fromJSON(inputs.node-versions || needs.versions.outputs.node) }}
shard: [1, 2]
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build CLI
working-directory: packages/cli
run: pnpm run build
- name: Run e2e tests (shard ${{ matrix.shard }})
working-directory: packages/cli
env:
SOCKET_CLI_API_TOKEN: ${{ secrets.SOCKET_CLI_API_TOKEN }}
run: pnpm run e2e-tests --shard=${{ matrix.shard }}/2