From 03cd88559901cf6ca1b455aef9b1dc6a936de68f Mon Sep 17 00:00:00 2001 From: Aleksandra Cynk Date: Tue, 23 Jul 2024 12:09:54 +0200 Subject: [PATCH 1/2] Extract value registry --- .../RuntimeTests/ReJest/RuntimeTestsApi.ts | 6 ++-- .../ReJest/TestRunner/TestRunner.ts | 24 --------------- .../ReJest/TestRunner/ValueRegistry.ts | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/ValueRegistry.ts diff --git a/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts b/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts index e40c2170539..eeefcda73ed 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts @@ -4,10 +4,12 @@ import type { TestComponent } from './TestComponent'; import type { SharedValue } from 'react-native-reanimated'; import type { TestConfiguration, TestValue, NullableTestValue, BuildFunction } from './types'; import { DescribeDecorator, TestDecorator } from './types'; +import { ValueRegistry } from './TestRunner/ValueRegistry'; export { Presets } from './Presets'; const testRunner = new TestRunner(); +const valueRegistry = new ValueRegistry(); type DescribeFunction = (name: string, buildSuite: BuildFunction) => void; type TestFunction = (name: string, buildTest: BuildFunction) => void; @@ -126,11 +128,11 @@ export function getTrackerCallCount(name: string) { } export function registerValue(name: string, value: SharedValue) { - return testRunner.registerValue(name, value); + return valueRegistry.registerValue(name, value); } export async function getRegisteredValue(name: string) { - return await testRunner.getRegisteredValue(name); + return await valueRegistry.getRegisteredValue(name); } export function getTestComponent(name: string): TestComponent { diff --git a/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts index eeb5ea5bd49..0b77492b7af 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts @@ -4,7 +4,6 @@ import type { BuildFunction, NullableTestValue, Operation, - SharedValueSnapshot, TestCase, TestConfiguration, TestSuite, @@ -22,7 +21,6 @@ import { indentNestingLevel, } from '../utils/stringFormatUtils'; import type { - SharedValue, LayoutAnimationStartFunction, LayoutAnimationType, SharedTransitionAnimationsValues, @@ -54,7 +52,6 @@ export class TestRunner { private _currentTestSuite: TestSuite | null = null; private _currentTestCase: TestCase | null = null; private _renderHook: (component: ReactElement | null) => void = () => {}; - private _valueRegistry: Record = {}; private _wasRenderedNull: boolean = false; private _includesOnly: boolean = false; private _syncUIRunner: SyncUIRunner = new SyncUIRunner(); @@ -209,27 +206,6 @@ export class TestRunner { } } - public registerValue(name: string, value: SharedValue) { - 'worklet'; - this._valueRegistry[name] = value; - } - - public async getRegisteredValue(name: string): Promise { - const jsValue = this._valueRegistry[name].value; - const sharedValue = this._valueRegistry[name]; - const valueContainer = makeMutable(null); - await this._syncUIRunner.runOnUIBlocking(() => { - 'worklet'; - valueContainer.value = sharedValue.value; - }, 1000); - const uiValue = valueContainer.value; - return { - name, - onJS: jsValue as TestValue, - onUI: uiValue as TestValue, - }; - } - public getTrackerCallCount(name: string): TrackerCallCount { return { name, diff --git a/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/ValueRegistry.ts b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/ValueRegistry.ts new file mode 100644 index 00000000000..deea9968957 --- /dev/null +++ b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/ValueRegistry.ts @@ -0,0 +1,30 @@ +import { makeMutable } from 'react-native-reanimated'; +import type { SharedValue } from 'react-native-reanimated'; +import type { SharedValueSnapshot, TestValue } from '../types'; +import { SyncUIRunner } from '../utils/SyncUIRunner'; + +export class ValueRegistry { + private _valueRegistry: Record = {}; + private _syncUIRunner = new SyncUIRunner(); + + public registerValue(name: string, value: SharedValue) { + 'worklet'; + this._valueRegistry[name] = value; + } + + public async getRegisteredValue(name: string): Promise { + const jsValue = this._valueRegistry[name].value; + const sharedValue = this._valueRegistry[name]; + const valueContainer = makeMutable(null); + await this._syncUIRunner.runOnUIBlocking(() => { + 'worklet'; + valueContainer.value = sharedValue.value; + }, 1000); + const uiValue = valueContainer.value; + return { + name, + onJS: jsValue as TestValue, + onUI: uiValue as TestValue, + }; + } +} From fe934fd80686882a4fa98133d94ee2d3331a14d1 Mon Sep 17 00:00:00 2001 From: Aleksandra Cynk Date: Mon, 29 Jul 2024 14:11:49 +0200 Subject: [PATCH 2/2] Make value registry a member of testRunner --- .../src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts | 3 +-- .../examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts b/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts index eeefcda73ed..265904b4034 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReJest/RuntimeTestsApi.ts @@ -4,12 +4,11 @@ import type { TestComponent } from './TestComponent'; import type { SharedValue } from 'react-native-reanimated'; import type { TestConfiguration, TestValue, NullableTestValue, BuildFunction } from './types'; import { DescribeDecorator, TestDecorator } from './types'; -import { ValueRegistry } from './TestRunner/ValueRegistry'; export { Presets } from './Presets'; const testRunner = new TestRunner(); -const valueRegistry = new ValueRegistry(); +const valueRegistry = testRunner.getValueRegistry(); type DescribeFunction = (name: string, buildSuite: BuildFunction) => void; type TestFunction = (name: string, buildTest: BuildFunction) => void; diff --git a/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts index 0b77492b7af..0f72ce05f6d 100644 --- a/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts +++ b/apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestRunner.ts @@ -31,6 +31,7 @@ import { assertMockedAnimationTimestamp, assertTestCase, assertTestSuite } from import { createUpdatesContainer } from './UpdatesContainer'; import { makeMutable, runOnJS } from 'react-native-reanimated'; import { RenderLock, SyncUIRunner } from '../utils/SyncUIRunner'; +import { ValueRegistry } from './ValueRegistry'; export { Presets } from '../Presets'; let callTrackerRegistryJS: Record = {}; @@ -56,6 +57,8 @@ export class TestRunner { private _includesOnly: boolean = false; private _syncUIRunner: SyncUIRunner = new SyncUIRunner(); private _renderLock: RenderLock = new RenderLock(); + private _valueRegistry = new ValueRegistry(); + private _summary: TestSummary = { passed: 0, failed: 0, @@ -65,6 +68,10 @@ export class TestRunner { endTime: 0, }; + public getValueRegistry() { + return this._valueRegistry; + } + public notify(name: string) { 'worklet'; if (_WORKLET) {