diff --git a/lib/app.ts b/lib/app.ts index 1c3c80f1..d058a7cf 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -97,7 +97,7 @@ async function init() { async function oclifRun(command: string[], options: AppOptions) { let deprecationPromise: Promise; // check and enforce the CLI's deprecation policy - if (unsupportedFlag) { + if (unsupportedFlag || process.env.BALENARC_UNSUPPORTED) { deprecationPromise = Promise.resolve(); } else { const { DeprecationChecker } = await import('./deprecation'); diff --git a/lib/deprecation.ts b/lib/deprecation.ts index 8a3d8bb7..183ee233 100644 --- a/lib/deprecation.ts +++ b/lib/deprecation.ts @@ -38,7 +38,6 @@ export interface ReleaseTimestampsByVersion { * https://jel.ly.fish/ed8d2395-9323-418c-bb67-d11d32a17d00 */ export class DeprecationChecker { - protected static disabled = false; // for the benefit of testing readonly majorVersionFetchIntervalDays = 7; readonly expiryDays = 365; readonly deprecationDays = Math.ceil(this.expiryDays / 2); @@ -131,7 +130,7 @@ or release date not available`); * `majorVersionFetchIntervalDays`. */ public async checkForNewReleasesIfNeeded() { - if (DeprecationChecker.disabled) { + if (process.env.BALENARC_UNSUPPORTED) { return; // for the benefit of code testing } await this.init(); @@ -182,7 +181,7 @@ or release date not available`); * in which case warn about it and conditionally throw an error. */ public async warnAndAbortIfDeprecated() { - if (DeprecationChecker.disabled) { + if (process.env.BALENARC_UNSUPPORTED) { return; // for the benefit of code testing } await this.init(); @@ -228,14 +227,4 @@ continue using this version of the CLI. However, note that the balenaCloud or openBalena backends may be updated in a way that is no longer compatible with this CLI version.`; } - - /** Disable deprecation checks (for the benefit of code testing). */ - public static disable() { - DeprecationChecker.disabled = true; - } - - /** Re-enable deprecation checks (for the benefit of code testing). */ - public static enable() { - DeprecationChecker.disabled = false; - } } diff --git a/tests/config-tests.ts b/tests/config-tests.ts index aa175e82..688595d5 100644 --- a/tests/config-tests.ts +++ b/tests/config-tests.ts @@ -23,8 +23,8 @@ setEsVersion('es2018'); process.env.BALENARC_NO_SENTRY = '1'; // Disable deprecation checks while running test code -import { DeprecationChecker } from '../build/deprecation'; -DeprecationChecker.disable(); +// Like the global `--unsupported` flag +process.env.BALENARC_UNSUPPORTED = '1'; import * as tmp from 'tmp'; tmp.setGracefulCleanup(); diff --git a/tests/deprecation.spec.ts b/tests/deprecation.spec.ts index c261bc87..b6848de3 100644 --- a/tests/deprecation.spec.ts +++ b/tests/deprecation.spec.ts @@ -54,10 +54,16 @@ describe('DeprecationChecker', function () { Parameters, ReturnType >; + let originalUnsupported: string | undefined; - // see also DeprecationChecker.disable() in tests/config-tests.ts - this.beforeAll(() => DeprecationChecker.enable()); - this.afterAll(() => DeprecationChecker.disable()); + this.beforeAll(() => { + // Temporarily undo settings from `tests/config-tests.ts` + originalUnsupported = process.env.BALENARC_UNSUPPORTED; + delete process.env.BALENARC_UNSUPPORTED; + }); + this.afterAll(() => { + process.env.BALENARC_UNSUPPORTED = originalUnsupported; + }); this.beforeEach(() => { npm = new NpmMock();