CLI test coverage upload returns connection error

Overview

The cs-coverage CLI tool returns a 'Connection error' when attempting to upload coverage data to CodeScene. This article explains how to diagnose and resolve connectivity issues with the coverage upload command.

Symptoms

  • Running cs-coverage upload returns 'Connection error!!!' immediately

  • Environment variables for CodeScene URL and API token are set

  • Coverage file itself is valid and the command syntax is correct

 

Root cause

A connection error from cs-coverage indicates the CLI cannot reach the CodeScene API endpoint. This is most commonly caused by: an incorrect or missing CODESCENE_URL environment variable (missing trailing slash, wrong port, or HTTP vs HTTPS mismatch), an API token that lacks the required permissions for coverage uploads, a corporate proxy that is not configured for CLI traffic, or a self-signed certificate on a self-hosted CodeScene instance that the CLI does not trust.

Resolution steps

  1. Verify the CODESCENE_URL environment variable is set correctly, e.g. export CODESCENE_URL=https://yourinstance.codescene.com (no trailing slash).

  2. Verify the CODESCENE_API_TOKEN variable is set and the token has the 'Coverage upload' scope enabled in CodeScene under User Settings → API Tokens.

  3. Test connectivity manually: curl -I $CODESCENE_URL/api/v1 — if this fails, the issue is network/DNS, not the CLI itself.

  4. If behind a corporate proxy, set the HTTP_PROXY and HTTPS_PROXY environment variables before running cs-coverage.

  5. For self-hosted instances with self-signed certificates, set the NODE_EXTRA_CA_CERTS environment variable to the path of your CA certificate file.

  6. Run cs-coverage with the --verbose flag if available to get more detailed error output, and share this with CodeScene support if the issue persists. 

Prevention

Add a connection check step to your CI pipeline that verifies CodeScene API reachability before running coverage uploads. Store the API token as a CI secret and validate it has the correct scopes as part of your CodeScene configuration documentation.