From 9f382b680135da83f291c44216241197464514f9 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Fri, 25 Nov 2022 10:58:56 +0100 Subject: [PATCH 1/4] feat: config option to allow breaking changes --- src/__tests__/config.test.ts | 1 + src/config.ts | 4 ++++ website/docs/API.md | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index 599e36da7..0bc21d77a 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -16,6 +16,7 @@ test('configure() overrides existing config values', () => { asyncUtilTimeout: 5000, defaultDebugOptions: { message: 'debug message' }, defaultIncludeHiddenElements: true, + allowBreakingChanges: false, }); }); diff --git a/src/config.ts b/src/config.ts index 0f3a8c22f..d0a8278b2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,6 +9,9 @@ export type Config = { /** Default options for `debug` helper. */ defaultDebugOptions?: Partial; + + /** Whether to allow RNTL to use latest and greatest improvements even if they are breaking changes. */ + allowBreakingChanges: boolean; }; export type ConfigAliasOptions = { @@ -19,6 +22,7 @@ export type ConfigAliasOptions = { const defaultConfig: Config = { asyncUtilTimeout: 1000, defaultIncludeHiddenElements: true, + allowBreakingChanges: false, }; let config = { ...defaultConfig }; diff --git a/website/docs/API.md b/website/docs/API.md index 3492fe399..423e8133e 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -52,6 +52,7 @@ title: API - [`asyncUtilTimeout` option](#asyncutiltimeout-option) - [`defaultIncludeHiddenElements` option](#defaultincludehiddenelements-option) - [`defaultDebugOptions` option](#defaultdebugoptions-option) + - [`allowBreakingChanges` option](#allowbreakingchanges-option) - [`resetToDefaults()`](#resettodefaults) - [Environment variables](#environment-variables) - [`RNTL_SKIP_AUTO_CLEANUP`](#rntl_skip_auto_cleanup) @@ -782,6 +783,7 @@ type Config = { asyncUtilTimeout: number; defaultHidden: boolean; defaultDebugOptions: Partial; + allowBreakingChanges: boolean; }; function configure(options: Partial) {} @@ -803,6 +805,9 @@ This option is also available as `defaultHidden` alias for compatibility with [R Default [debug options](#debug) to be used when calling `debug()`. These default options will be overridden by the ones you specify directly when calling `debug()`. +#### `allowBreakingChanges` option + +By default RNTL is using SemVer practices that require a major version update in case of any breaking changes. If you set this option to `true` you will be allowed to use latest RNTL API that might contain breaking changes. These breaking changes are planned to become default in the next major release. APIs that would be affected by this option will have that documented. ### `resetToDefaults()` ```ts From 095552f5397bb2b567947fc3ee95224398a5ae01 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Tue, 29 Nov 2022 10:20:07 +0100 Subject: [PATCH 2/4] refactor: make allowBreakingChanges internal configuration option --- src/__tests__/config.test.ts | 18 +++++++++++++++++- src/config.ts | 25 ++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index 0bc21d77a..a8f1bb4a0 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -1,10 +1,16 @@ -import { getConfig, configure, resetToDefaults } from '../config'; +import { + getConfig, + configure, + resetToDefaults, + configureInternal, +} from '../config'; beforeEach(() => { resetToDefaults(); }); test('getConfig() returns existing configuration', () => { + expect(getConfig().allowBreakingChanges).toEqual(false); expect(getConfig().asyncUtilTimeout).toEqual(1000); expect(getConfig().defaultIncludeHiddenElements).toEqual(true); }); @@ -33,6 +39,16 @@ test('resetToDefaults() resets config to defaults', () => { expect(getConfig().defaultIncludeHiddenElements).toEqual(true); }); +test('resetToDefaults() resets internal config to defaults', () => { + configureInternal({ + allowBreakingChanges: true, + }); + expect(getConfig().allowBreakingChanges).toEqual(true); + + resetToDefaults(); + expect(getConfig().allowBreakingChanges).toEqual(false); +}); + test('configure handles alias option defaultHidden', () => { expect(getConfig().defaultIncludeHiddenElements).toEqual(true); diff --git a/src/config.ts b/src/config.ts index d0a8278b2..65364c9fb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,8 @@ import { DebugOptions } from './helpers/debugDeep'; +/** + * Global configuration options for React Native Testing Library. + */ export type Config = { /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */ asyncUtilTimeout: number; @@ -9,9 +12,6 @@ export type Config = { /** Default options for `debug` helper. */ defaultDebugOptions?: Partial; - - /** Whether to allow RNTL to use latest and greatest improvements even if they are breaking changes. */ - allowBreakingChanges: boolean; }; export type ConfigAliasOptions = { @@ -19,14 +19,22 @@ export type ConfigAliasOptions = { defaultHidden: boolean; }; -const defaultConfig: Config = { +export type InternalConfig = Config & { + /** Whether to allow RNTL to use latest and greatest improvements even if they are breaking changes. */ + allowBreakingChanges: boolean; +}; + +const defaultConfig: InternalConfig = { + allowBreakingChanges: false, asyncUtilTimeout: 1000, defaultIncludeHiddenElements: true, - allowBreakingChanges: false, }; let config = { ...defaultConfig }; +/** + * Configure global options for React Native Testing Library. + */ export function configure(options: Partial) { const { defaultHidden, ...restOptions } = options; @@ -42,6 +50,13 @@ export function configure(options: Partial) { }; } +export function configureInternal(option: Partial) { + config = { + ...config, + ...option, + }; +} + export function resetToDefaults() { config = { ...defaultConfig }; } From 954c7a60d884353b3e429351f955e57e79fbfab0 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Tue, 29 Nov 2022 10:27:32 +0100 Subject: [PATCH 3/4] chore: remove docs --- website/docs/API.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/website/docs/API.md b/website/docs/API.md index 423e8133e..3492fe399 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -52,7 +52,6 @@ title: API - [`asyncUtilTimeout` option](#asyncutiltimeout-option) - [`defaultIncludeHiddenElements` option](#defaultincludehiddenelements-option) - [`defaultDebugOptions` option](#defaultdebugoptions-option) - - [`allowBreakingChanges` option](#allowbreakingchanges-option) - [`resetToDefaults()`](#resettodefaults) - [Environment variables](#environment-variables) - [`RNTL_SKIP_AUTO_CLEANUP`](#rntl_skip_auto_cleanup) @@ -783,7 +782,6 @@ type Config = { asyncUtilTimeout: number; defaultHidden: boolean; defaultDebugOptions: Partial; - allowBreakingChanges: boolean; }; function configure(options: Partial) {} @@ -805,9 +803,6 @@ This option is also available as `defaultHidden` alias for compatibility with [R Default [debug options](#debug) to be used when calling `debug()`. These default options will be overridden by the ones you specify directly when calling `debug()`. -#### `allowBreakingChanges` option - -By default RNTL is using SemVer practices that require a major version update in case of any breaking changes. If you set this option to `true` you will be allowed to use latest RNTL API that might contain breaking changes. These breaking changes are planned to become default in the next major release. APIs that would be affected by this option will have that documented. ### `resetToDefaults()` ```ts From 541eb2b7b0dfd8c7f730d6e84e9a82ea8f24b5e6 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Tue, 29 Nov 2022 13:26:17 +0100 Subject: [PATCH 4/4] chore: code review changes --- src/__tests__/config.test.ts | 10 +++++----- src/config.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index a8f1bb4a0..c197b9c3a 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -10,7 +10,7 @@ beforeEach(() => { }); test('getConfig() returns existing configuration', () => { - expect(getConfig().allowBreakingChanges).toEqual(false); + expect(getConfig().useBreakingChanges).toEqual(false); expect(getConfig().asyncUtilTimeout).toEqual(1000); expect(getConfig().defaultIncludeHiddenElements).toEqual(true); }); @@ -22,7 +22,7 @@ test('configure() overrides existing config values', () => { asyncUtilTimeout: 5000, defaultDebugOptions: { message: 'debug message' }, defaultIncludeHiddenElements: true, - allowBreakingChanges: false, + useBreakingChanges: false, }); }); @@ -41,12 +41,12 @@ test('resetToDefaults() resets config to defaults', () => { test('resetToDefaults() resets internal config to defaults', () => { configureInternal({ - allowBreakingChanges: true, + useBreakingChanges: true, }); - expect(getConfig().allowBreakingChanges).toEqual(true); + expect(getConfig().useBreakingChanges).toEqual(true); resetToDefaults(); - expect(getConfig().allowBreakingChanges).toEqual(false); + expect(getConfig().useBreakingChanges).toEqual(false); }); test('configure handles alias option defaultHidden', () => { diff --git a/src/config.ts b/src/config.ts index 65364c9fb..64de13d13 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,12 +20,12 @@ export type ConfigAliasOptions = { }; export type InternalConfig = Config & { - /** Whether to allow RNTL to use latest and greatest improvements even if they are breaking changes. */ - allowBreakingChanges: boolean; + /** Whether to use breaking changes intended for next major version release. */ + useBreakingChanges: boolean; }; const defaultConfig: InternalConfig = { - allowBreakingChanges: false, + useBreakingChanges: false, asyncUtilTimeout: 1000, defaultIncludeHiddenElements: true, };