From 4ef326ef1954d1f3b97260928aca159a7e030dd9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 31 Jul 2026 17:08:31 +0000 Subject: [PATCH] docs: document that unit tests require TEST_SNYK_TOKEN Co-authored-by: Ben Durrans --- AGENTS.md | 6 ++++-- CONTRIBUTING.md | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 132d588f10..21b0be462f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,8 +177,8 @@ The CLI follows a layered testing pyramid. Each layer has a different goal, syst ## Running Tests ```sh -# TypeScript unit tests -npm run test:unit +# TypeScript unit tests (some suites validate credentials, so a token is required) +TEST_SNYK_TOKEN= npm run test:unit # TypeScript acceptance/user journey tests (requires a built binary) TEST_SNYK_COMMAND=./binary-releases/snyk-macos-arm64 npm run test:acceptance @@ -191,6 +191,8 @@ cd cliv2 && make test npx jest --runInBand test/jest/unit/path/to/test.spec.ts ``` +`SNYK_TOKEN` is **not** an alternative to `TEST_SNYK_TOKEN` — `test/setup.js` removes `SNYK_TOKEN` (and `SNYK_API_KEY`) from the environment when either is set, and writes `TEST_SNYK_TOKEN` into the CLI user config so tests run against a known configuration. + ## Running the CLI Locally ```sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08919bfea0..f3b2c90f1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -156,6 +156,13 @@ Avoid using mocks as these can go out of sync and be challenging to maintain; pr If you are mostly testing functions calling other functions, consider writing an acceptance test instead. Otherwise, your tests will likely mirror the implementation and rely heavily on mocks; making future changes difficult. +Despite the above, `npm run test:unit` currently needs `TEST_SNYK_TOKEN` set to a +[valid API token](https://docs.snyk.io/snyk-api/authentication-for-api). A handful of suites drive command entry points +that validate credentials before doing anything else, so without it they fail with `MissingApiTokenError`. Note that +setting `SNYK_TOKEN` does not work: [`test/setup.js`](./test/setup.js) removes `SNYK_TOKEN` (and `SNYK_API_KEY`) from the +environment when either is set, and separately writes `TEST_SNYK_TOKEN` into the CLI user config so tests run against a +known configuration rather than whatever the developer happens to be authenticated as. + ### Acceptance tests Acceptance tests enforce the correctness of our distribution and are written from the perspective of a user.