Skip to content

Commit

Permalink
fix: deprecated settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Apr 9, 2024
1 parent 28714a6 commit f325797
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
*/
import { addKnownWarn, consoleSpy } from '@cloudbeaver/tests-runner';

const DEPRECATED_SETTING_MESSAGE_REGEX = /You are using deprecated settings.*/;
const DEPRECATED_SETTING_MESSAGE_REGEX = /You have deprecated settings:*/;

beforeAll(async () => {
addKnownWarn(DEPRECATED_SETTING_MESSAGE_REGEX);
});

export function expectDeprecatedSettingMessage(deprecated?: string, key?: string) {
if (deprecated && key) {
expect(consoleSpy.warn).toHaveBeenCalledWith(expect.stringMatching(`You are using deprecated settings: "${deprecated}". Use "${key}" instead.`));
expect(consoleSpy.warn).toHaveBeenCalledWith(expect.stringMatching(`You have deprecated settings: "${deprecated}". Use "${key}" instead.`));
} else {
expect(consoleSpy.warn).toHaveBeenCalledWith(expect.stringMatching(DEPRECATED_SETTING_MESSAGE_REGEX));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '@testing-library/jest-dom';

import { SyncExecutor } from '@cloudbeaver/core-executor';

import { expectDeprecatedSettingMessage } from './__custom_mocks__/expectDeprecatedSettingMessage';
import { expectDeprecatedSettingMessage, expectNoDeprecatedSettingMessage } from './__custom_mocks__/expectDeprecatedSettingMessage';
import { createSettingsAliasResolver } from './createSettingsAliasResolver';
import type { ISettingsSource } from './ISettingsSource';

Expand Down Expand Up @@ -52,9 +52,16 @@ function createResolver(settings: Record<any, any>) {
});
}

test('Deprecated setting extracted', async () => {
test('Deprecated setting ignored', async () => {
const resolver = createResolver(newSettings);

expect(resolver.has('value')).toBe(false);
expectNoDeprecatedSettingMessage();
});

test('Deprecated setting extracted', async () => {
const resolver = createResolver(deprecatedSettings);

expect(resolver.has('value')).toBe(true);
expect(resolver.getValue('value')).toBe('deprecatedValue');
expectDeprecatedSettingMessage('deprecated', 'value');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function createSettingsAliasResolver<TTarget extends schema.SomeZodObject
const oldKey = mapKey(key);
const has = source.has(oldKey);

if (!DEPRECATED_SETTINGS.has(oldKey)) {
if (has && !DEPRECATED_SETTINGS.has(oldKey)) {
console.warn(`You have deprecated settings: "${String(oldKey)}". Use "${key}" instead.`);
DEPRECATED_SETTINGS.add(oldKey);
}
Expand Down

0 comments on commit f325797

Please sign in to comment.