Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions packages/react-native-fantom/runtime/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const rootContext: Context = {
beforeAllHooks: [],
beforeEachHooks: [],
afterAllHooks: [],
afterEachHooks: [],
afterEachHooks: [validateEmptyMessageQueue],
children: [],
focused: false,
skipped: false,
Expand All @@ -93,8 +93,8 @@ const globalDescribe = (global.describe = (
beforeAllHooks: [],
beforeEachHooks: [],
children: [],
focused: focused,
skipped: skipped,
focused,
skipped,
};
currentContext.children.push(childContext);
currentContext = childContext;
Expand Down Expand Up @@ -137,8 +137,8 @@ const globalIt =
title,
parentContext: currentContext,
implementation,
focused: focused,
skipped: skipped,
focused,
skipped,
});
});

Expand Down Expand Up @@ -388,6 +388,10 @@ function reportTestSuiteResult(testSuiteResult: TestSuiteResult): void {
);
}

function validateEmptyMessageQueue(): void {
NativeFantom.validateEmptyMessageQueue();
}

global.$$RunTests$$ = () => {
reportTestSuiteResult({
testResults: runSuite(currentContext),
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native-fantom/src/__tests__/Fantom-itest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {Root} from '..';
import Fantom from '..';
import * as React from 'react';
import {ScrollView, Text, TextInput, View} from 'react-native';
import NativeFantom from 'react-native/src/private/specs/modules/NativeFantom';
import ensureInstance from 'react-native/src/private/utilities/ensureInstance';
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';

Expand Down Expand Up @@ -132,6 +133,16 @@ describe('Fantom', () => {
});
expect(threw).toBe(true);
});

it('should error when any scheduled tasks remain after the test', () => {
Fantom.scheduleTask(() => {});
expect(() => NativeFantom.validateEmptyMessageQueue()).toThrow(
'Exception in HostFunction: MessageQueue is not empty',
);

// Flushing queue to avoid this test failing
Fantom.runWorkLoop();
});
});

describe('createRoot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10482,6 +10482,7 @@ interface Spec extends TurboModule {
getMountingManagerLogs: (surfaceId: number) => Array<string>;
flushMessageQueue: () => void;
flushEventQueue: () => void;
validateEmptyMessageQueue: () => void;
getRenderedOutput: (surfaceId: number, config: RenderFormatOptions) => string;
reportTestSuiteResultsJSON: (results: string) => void;
}
Expand Down
16 changes: 0 additions & 16 deletions packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ inline bool isYogaStyleProp(const std::string& prop) {
}
} // namespace

RawProps::RawProps() {
mode_ = Mode::Empty;
}

/*
* Creates an object with given `runtime` and `value`.
*/
Expand Down Expand Up @@ -149,18 +145,6 @@ RawProps::RawProps(const RawProps& other) noexcept {
ignoreYogaStyleProps_ = other.ignoreYogaStyleProps_;
}

RawProps& RawProps::operator=(const RawProps& other) noexcept {
mode_ = other.mode_;
if (mode_ == Mode::JSI) {
runtime_ = other.runtime_;
value_ = jsi::Value(*runtime_, other.value_);
} else if (mode_ == Mode::Dynamic) {
dynamic_ = other.dynamic_;
}
ignoreYogaStyleProps_ = other.ignoreYogaStyleProps_;
return *this;
}

void RawProps::parse(const RawPropsParser& parser) noexcept {
react_native_assert(parser_ == nullptr && "A parser was already assigned.");
parser_ = &parser;
Expand Down
11 changes: 6 additions & 5 deletions packages/react-native/ReactCommon/react/renderer/core/RawProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ class RawProps final {
/*
* Creates empty RawProps objects.
*/
RawProps();
RawProps() : mode_(Mode::Empty) {}

/*
* Creates an object with given `runtime` and `value`.
*/
RawProps(jsi::Runtime& runtime, const jsi::Value& value) noexcept;

explicit RawProps(const RawProps& rawProps) noexcept;
RawProps& operator=(const RawProps& other) noexcept;

RawProps(RawProps&& other) noexcept = default;
RawProps& operator=(RawProps&& other) noexcept = default;

RawProps& operator=(const RawProps& other) noexcept = delete;
RawProps& operator=(RawProps&& other) noexcept = delete;

/*
* Creates an object with given `folly::dynamic` object.
Expand Down Expand Up @@ -112,8 +112,9 @@ class RawProps final {
/*
* Source artefacts:
*/

// Mode
mutable Mode mode_;
Mode mode_;

// Case 1: Source data is represented as `jsi::Object`.
jsi::Runtime* runtime_{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ interface Spec extends TurboModule {
getMountingManagerLogs: (surfaceId: number) => Array<string>;
flushMessageQueue: () => void;
flushEventQueue: () => void;
validateEmptyMessageQueue: () => void;
getRenderedOutput: (surfaceId: number, config: RenderFormatOptions) => string;
reportTestSuiteResultsJSON: (results: string) => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1507,16 +1507,18 @@ describe('IntersectionObserver', () => {

const node = ensureReactNativeElement(maybeNode);

observer1 = new IntersectionObserver(() => {});
observer2 = new IntersectionObserver(() => {});
Fantom.runTask(() => {
observer1 = new IntersectionObserver(() => {});
observer2 = new IntersectionObserver(() => {});

observer1.observe(node);
observer2.observe(node);
observer1.observe(node);
observer2.observe(node);

observer1.unobserve(node);
observer1.unobserve(node);

// The second call shouldn't log errors (that would make the test fail).
observer2.unobserve(node);
// The second call shouldn't log errors (that would make the test fail).
observer2.unobserve(node);
});
});
});

Expand Down