Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract valueRegistry from TestRunner #6317

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Latropos marked this conversation as resolved.
Show resolved Hide resolved

type DescribeFunction = (name: string, buildSuite: BuildFunction) => void;
type TestFunction = (name: string, buildTest: BuildFunction) => void;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
BuildFunction,
NullableTestValue,
Operation,
SharedValueSnapshot,
TestCase,
TestConfiguration,
TestSuite,
Expand All @@ -22,7 +21,6 @@ import {
indentNestingLevel,
} from '../utils/stringFormatUtils';
import type {
SharedValue,
LayoutAnimationStartFunction,
LayoutAnimationType,
SharedTransitionAnimationsValues,
Expand Down Expand Up @@ -54,7 +52,6 @@ export class TestRunner {
private _currentTestSuite: TestSuite | null = null;
private _currentTestCase: TestCase | null = null;
private _renderHook: (component: ReactElement<Component> | null) => void = () => {};
private _valueRegistry: Record<string, SharedValue> = {};
private _wasRenderedNull: boolean = false;
private _includesOnly: boolean = false;
private _syncUIRunner: SyncUIRunner = new SyncUIRunner();
Expand Down Expand Up @@ -209,27 +206,6 @@ export class TestRunner {
}
}

public registerValue(name: string, value: SharedValue) {
'worklet';
this._valueRegistry[name] = value;
}

public async getRegisteredValue(name: string): Promise<SharedValueSnapshot> {
const jsValue = this._valueRegistry[name].value;
const sharedValue = this._valueRegistry[name];
const valueContainer = makeMutable<unknown>(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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, SharedValue> = {};
private _syncUIRunner = new SyncUIRunner();

public registerValue(name: string, value: SharedValue) {
'worklet';
this._valueRegistry[name] = value;
}

public async getRegisteredValue(name: string): Promise<SharedValueSnapshot> {
const jsValue = this._valueRegistry[name].value;
const sharedValue = this._valueRegistry[name];
const valueContainer = makeMutable<unknown>(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,
};
}
}
Loading