From ebd711ff66bdfe20f4c22a0eeced541bcb5e9fe5 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 7 Oct 2026 20:11:46 +0100 Subject: [PATCH] Deprecate `isInTestMode` in favour of a more clearly named method --- lib/entry-points.js | 11 ++++++++++- src/environment.ts | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 258262f2d..415f8beff 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -166145,6 +166145,15 @@ var ReadOnlyEnv = class { entries() { return Object.entries(this.vars); } + /** + * Gets a value indicating whether we should skip uploads of + * all kinds (SARIF results, status reports, DBs, ...). + * + * This is not guaranteed to be set in all test environments. + */ + isSkippingUploadsInTests() { + return this.getOptional("CODEQL_ACTION_TEST_MODE" /* TEST_MODE */) === "true"; + } /** * Gets a value indicative of whether we are in a testing environment * by testing whether the value of the `NODE_ENV` variable is "test". @@ -166185,7 +166194,7 @@ function getEnv(env = process.env) { return new Env(env); } function isInTestMode() { - return process.env["CODEQL_ACTION_TEST_MODE" /* TEST_MODE */] === "true"; + return getEnv().isSkippingUploadsInTests(); } function exportVariable2(name, val) { const env = getEnv(); diff --git a/src/environment.ts b/src/environment.ts index 4a68e76be..ed88e96bd 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -304,6 +304,16 @@ export class ReadOnlyEnv { return Object.entries(this.vars); } + /** + * Gets a value indicating whether we should skip uploads of + * all kinds (SARIF results, status reports, DBs, ...). + * + * This is not guaranteed to be set in all test environments. + */ + public isSkippingUploadsInTests(): boolean { + return this.getOptional(EnvVar.TEST_MODE) === "true"; + } + /** * Gets a value indicative of whether we are in a testing environment * by testing whether the value of the `NODE_ENV` variable is "test". @@ -366,9 +376,14 @@ export function getEnv(env: NodeJS.ProcessEnv = process.env): Env { * Returns whether we are in test mode. This is used by CodeQL Action PR checks. * * In test mode, we skip several uploads (SARIF results, status reports, DBs, ...). + * + * @deprecated + * The purpose of this function is ambiguous. Use `isSkippingUploadsInTests` on + * a `ReadOnlyEnv` instance instead for equivalent behaviour. Use `isTestingEnv` + * to determine if we are running in a unit test. */ export function isInTestMode(): boolean { - return process.env[EnvVar.TEST_MODE] === "true"; + return getEnv().isSkippingUploadsInTests(); } /**