Skip to content

Commit ebd711f

Browse files
committed
Deprecate isInTestMode in favour of a more clearly named method
1 parent 75ea4cb commit ebd711f

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/environment.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ export class ReadOnlyEnv<T extends string | undefined = string | undefined> {
304304
return Object.entries(this.vars);
305305
}
306306

307+
/**
308+
* Gets a value indicating whether we should skip uploads of
309+
* all kinds (SARIF results, status reports, DBs, ...).
310+
*
311+
* This is not guaranteed to be set in all test environments.
312+
*/
313+
public isSkippingUploadsInTests(): boolean {
314+
return this.getOptional(EnvVar.TEST_MODE) === "true";
315+
}
316+
307317
/**
308318
* Gets a value indicative of whether we are in a testing environment
309319
* 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 {
366376
* Returns whether we are in test mode. This is used by CodeQL Action PR checks.
367377
*
368378
* In test mode, we skip several uploads (SARIF results, status reports, DBs, ...).
379+
*
380+
* @deprecated
381+
* The purpose of this function is ambiguous. Use `isSkippingUploadsInTests` on
382+
* a `ReadOnlyEnv` instance instead for equivalent behaviour. Use `isTestingEnv`
383+
* to determine if we are running in a unit test.
369384
*/
370385
export function isInTestMode(): boolean {
371-
return process.env[EnvVar.TEST_MODE] === "true";
386+
return getEnv().isSkippingUploadsInTests();
372387
}
373388

374389
/**

0 commit comments

Comments
 (0)