mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Avoid NockMock warnings during standalone executable testing
Change-type: patch
This commit is contained in:
parent
6cfff72c59
commit
be306e6a20
@ -97,7 +97,7 @@ async function init() {
|
||||
async function oclifRun(command: string[], options: AppOptions) {
|
||||
let deprecationPromise: Promise<void>;
|
||||
// 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');
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -54,10 +54,16 @@ describe('DeprecationChecker', function () {
|
||||
Parameters<typeof mockStorage.set>,
|
||||
ReturnType<typeof mockStorage.set>
|
||||
>;
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user