Skip to content

Commit ef36f07

Browse files
authored
fix: fixed versions assertion (DevExpress#30044) (DevExpress#30626)
1 parent 9d1e1fe commit ef36f07

File tree

5 files changed

+113
-15
lines changed

5 files changed

+113
-15
lines changed

packages/devextreme/js/__internal/core/license/license_validation.test.ts

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import config from '@js/core/config';
55
import errors from '@js/core/errors';
66

77
import { base } from '../../ui/overlay/z_index';
8-
import { assertDevExtremeVersion, clearAssertedVersions } from '../../utils/version';
8+
import {
9+
assertDevExtremeVersion,
10+
assertedVersionsCompatible,
11+
clearAssertedVersions,
12+
} from '../../utils/version';
913
import {
1014
parseLicenseKey,
1115
setLicenseCheckSkipCondition,
@@ -535,3 +539,85 @@ describe('DevExpress license check', () => {
535539
expect(trialPanelSpy).toHaveBeenCalled();
536540
});
537541
});
542+
543+
describe('assertedVersions integration', () => {
544+
const packages = [{ packageName: 'test-package', version: '1.2.3' }];
545+
546+
beforeEach(() => {
547+
jest.resetModules();
548+
jest.spyOn(errors, 'log').mockImplementation(() => {});
549+
});
550+
551+
afterEach(() => {
552+
jest.restoreAllMocks();
553+
delete globalThis.DevExpress;
554+
clearAssertedVersions();
555+
});
556+
557+
describe('set version in assertDevExtremeVersion', () => {
558+
test('returns false and logs error when asserted versions are not compatible', () => {
559+
assertDevExtremeVersion('test-package', '1.2.3');
560+
561+
const result = assertedVersionsCompatible({ major: 2, minor: 0, patch: 0 });
562+
563+
expect(result).toBe(false);
564+
expect(errors.log).toHaveBeenCalledWith('W0023', expect.stringContaining('test-package'));
565+
});
566+
567+
test('returns true when asserted versions are compatible', () => {
568+
assertDevExtremeVersion('test-package', '1.2.3');
569+
570+
const result = assertedVersionsCompatible({ major: 1, minor: 2, patch: 3 });
571+
572+
expect(result).toBe(true);
573+
expect(errors.log).not.toHaveBeenCalled();
574+
});
575+
576+
test('clears asserted versions from config', () => {
577+
assertDevExtremeVersion('test-package-2', '1.2.3');
578+
clearAssertedVersions();
579+
580+
expect(config().versionAssertions).toEqual([]);
581+
});
582+
});
583+
584+
describe('set version in DevExpress.config', () => {
585+
test('returns true when all global version assertions are compatible', () => {
586+
globalThis.DevExpress = {
587+
config: {
588+
versionAssertions: packages,
589+
},
590+
};
591+
592+
// eslint-disable-next-line
593+
const versionUtils = require('@js/__internal/utils/version');
594+
// eslint-disable-next-line
595+
const errors = require('@js/core/errors').default;
596+
jest.spyOn(errors, 'log').mockImplementation(() => {});
597+
598+
const result = versionUtils.assertedVersionsCompatible({ major: 1, minor: 2, patch: 3 });
599+
600+
expect(result).toBe(true);
601+
expect(errors.log).not.toHaveBeenCalled();
602+
});
603+
604+
test('returns false and log error when any global version assertion is not compatible', () => {
605+
globalThis.DevExpress = {
606+
config: {
607+
versionAssertions: packages,
608+
},
609+
};
610+
611+
// eslint-disable-next-line
612+
const versionUtils = require('@js/__internal/utils/version');
613+
// eslint-disable-next-line
614+
const errors = require('@js/core/errors').default;
615+
jest.spyOn(errors, 'log').mockImplementation(() => {});
616+
617+
const result = versionUtils.assertedVersionsCompatible({ major: 2, minor: 0, patch: 0 });
618+
619+
expect(result).toBe(false);
620+
expect(errors.log).toHaveBeenCalledWith('W0023', expect.stringContaining('test-package'));
621+
});
622+
});
623+
});

packages/devextreme/js/__internal/core/m_config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const config = {
1717
useJQuery: undefined,
1818
editorStylingMode: undefined,
1919
useLegacyVisibleIndex: false,
20+
versionAssertions: [],
2021

2122
floatingActionButtonConfig: {
2223
icon: 'add',
@@ -76,6 +77,7 @@ const configMethod = (...args) => {
7677

7778
extend(config, newConfig);
7879
};
80+
7981
// @ts-expect-error typescript cant see global
8082
if (typeof DevExpress !== 'undefined' && DevExpress.config) {
8183
// @ts-expect-error typescript cant see global

packages/devextreme/js/__internal/utils/version.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1+
import type { VersionAssertion } from '@js/common';
2+
import config from '@js/core/config';
13
import errors from '@js/core/errors';
24

35
const MAX_MINOR_VERSION = 2;
46
const MIN_MINOR_VERSION = 1;
57

6-
interface AssertedVersion {
7-
packageName: string;
8-
version: string;
9-
}
10-
11-
const assertedVersions: AssertedVersion[] = [];
12-
138
export interface Version {
149
major: number;
1510
minor: number;
@@ -34,20 +29,21 @@ export function parseVersion(version: string): Version {
3429
};
3530
}
3631

32+
export function getAssertedVersions(): VersionAssertion[] {
33+
return config()?.versionAssertions ?? [];
34+
}
35+
3736
export function assertDevExtremeVersion(packageName: string, version: string): void {
38-
assertedVersions.push({
39-
packageName,
40-
version,
41-
});
37+
config({ versionAssertions: [...getAssertedVersions(), { packageName, version }] });
4238
}
4339

4440
export function clearAssertedVersions(): void {
4541
/// #DEBUG
46-
assertedVersions.splice(0);
42+
config({ versionAssertions: [] });
4743
/// #ENDDEBUG
4844
}
4945

50-
function stringifyVersionList(assertedVersionList: AssertedVersion[]): string {
46+
function stringifyVersionList(assertedVersionList: VersionAssertion[]): string {
5147
return assertedVersionList
5248
.map((assertedVersion) => `${assertedVersion.packageName}: ${assertedVersion.version}`)
5349
.join('\n');
@@ -76,7 +72,7 @@ export function getPreviousMajorVersion({ major, minor, patch }: Version): Versi
7672
}
7773

7874
export function assertedVersionsCompatible(currentVersion: Version): boolean {
79-
const mismatchingVersions = assertedVersions.filter(
75+
const mismatchingVersions = getAssertedVersions().filter(
8076
(assertedVersion) => !versionsEqual(
8177
parseVersion(assertedVersion.version),
8278
currentVersion,

packages/devextreme/js/common.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ export type FirstDayOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6;
270270
*/
271271
export type Format = 'billions' | 'currency' | 'day' | 'decimal' | 'exponential' | 'fixedPoint' | 'largeNumber' | 'longDate' | 'longTime' | 'millions' | 'millisecond' | 'month' | 'monthAndDay' | 'monthAndYear' | 'percent' | 'quarter' | 'quarterAndYear' | 'shortDate' | 'shortTime' | 'thousands' | 'trillions' | 'year' | 'dayOfWeek' | 'hour' | 'longDateLongTime' | 'minute' | 'second' | 'shortDateShortTime';
272272

273+
export type VersionAssertion = {
274+
packageName: string;
275+
version: string;
276+
};
277+
273278
/**
274279
* @docid
275280
* @section commonObjectStructures
@@ -278,6 +283,7 @@ export type Format = 'billions' | 'currency' | 'day' | 'decimal' | 'exponential'
278283
* @type object
279284
*/
280285
export type GlobalConfig = {
286+
versionAssertions?: VersionAssertion[];
281287
/**
282288
* @docid
283289
* @default "."

packages/devextreme/ts/dx.all.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,13 @@ declare module DevExpress {
862862
*/
863863
static validateModel(model: any): any;
864864
}
865+
/**
866+
* @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution.
867+
*/
868+
export type VersionAssertion = {
869+
packageName: string;
870+
version: string;
871+
};
865872
}
866873
declare module DevExpress.aiIntegration {
867874
/**
@@ -1264,6 +1271,7 @@ declare module DevExpress.common {
12641271
* [descr:GlobalConfig]
12651272
*/
12661273
export type GlobalConfig = {
1274+
versionAssertions?: VersionAssertion[];
12671275
/**
12681276
* [descr:GlobalConfig.decimalSeparator]
12691277
* @deprecated [depNote:GlobalConfig.decimalSeparator]

0 commit comments

Comments
 (0)