diff --git a/packages/react-native-fantom/runner/EnvironmentOptions.js b/packages/react-native-fantom/runner/EnvironmentOptions.js new file mode 100644 index 000000000000..18c9173c6b76 --- /dev/null +++ b/packages/react-native-fantom/runner/EnvironmentOptions.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + * @oncall react_native + */ + +export const printCLIOutput: boolean = Boolean(process.env.FANTOM_PRINT_OUTPUT); + +export const logCommands: boolean = Boolean(process.env.FANTOM_LOG_COMMANDS); + +export const enableCppDebugging: boolean = Boolean( + process.env.FANTOM_ENABLE_CPP_DEBUGGING, +); diff --git a/packages/react-native-fantom/runner/runner.js b/packages/react-native-fantom/runner/runner.js index 776ee43957b3..3c2703504430 100644 --- a/packages/react-native-fantom/runner/runner.js +++ b/packages/react-native-fantom/runner/runner.js @@ -10,8 +10,10 @@ */ import type {TestSuiteResult} from '../runtime/setup'; +import type {AsyncCommandResult} from './utils'; import entrypointTemplate from './entrypoint-template'; +import * as EnvironmentOptions from './EnvironmentOptions'; import getFantomTestConfig from './getFantomTestConfig'; import {FantomTestConfigMode} from './getFantomTestConfig'; import { @@ -22,7 +24,9 @@ import { getBuckModesForPlatform, getDebugInfoFromCommandResult, getShortHash, + printConsoleLog, runBuck2, + runBuck2Sync, symbolicateStackTrace, } from './utils'; import fs from 'fs'; @@ -32,6 +36,7 @@ import {SnapshotState, buildSnapshotResolver} from 'jest-snapshot'; import Metro from 'metro'; import nullthrows from 'nullthrows'; import path from 'path'; +import readline from 'readline'; const BUILD_OUTPUT_ROOT = path.resolve(__dirname, '..', 'build'); fs.mkdirSync(BUILD_OUTPUT_ROOT, {recursive: true}); @@ -39,33 +44,81 @@ const BUILD_OUTPUT_PATH = fs.mkdtempSync( path.join(BUILD_OUTPUT_ROOT, `run-${Date.now()}-`), ); -const PRINT_FANTOM_OUTPUT: false = false; +async function processRNTesterCommandResult( + result: AsyncCommandResult, +): Promise { + const stdoutChunks = []; + const stderrChunks = []; -function parseRNTesterCommandResult(result: ReturnType): { - logs: string, - testResult: TestSuiteResult, -} { - const stdout = result.stdout.toString(); - - const outputArray = stdout - .trim() - .split('\n') - .filter(log => !log.startsWith('Running "')); // remove AppRegistry logs. + result.childProcess.stdout.on('data', chunk => { + stdoutChunks.push(chunk); + }); - // The last line should be the test output in JSON format - const testResultJSON = outputArray.pop(); + result.childProcess.stderr.on('data', chunk => { + stderrChunks.push(chunk); + }); let testResult; - try { - testResult = JSON.parse(nullthrows(testResultJSON)); - } catch (error) { + + const rl = readline.createInterface({input: result.childProcess.stdout}); + rl.on('line', (rawLine: string) => { + const line = rawLine.trim(); + if (!line) { + return; + } + + let parsed; + try { + parsed = JSON.parse(line); + } catch { + parsed = { + type: 'console-log', + level: 'info', + message: line, + }; + } + + switch (parsed?.type) { + case 'test-result': + testResult = parsed; + break; + case 'console-log': + printConsoleLog(parsed); + break; + default: + printConsoleLog({ + type: 'console-log', + level: 'info', + message: line, + }); + break; + } + }); + + await result.done; + + const getResultWithOutput = () => ({ + ...result, + stdout: stdoutChunks.join(''), + stderr: stderrChunks.join(''), + }); + + if (result.status !== 0) { + throw new Error(getDebugInfoFromCommandResult(getResultWithOutput())); + } + + if (EnvironmentOptions.printCLIOutput) { + console.log(getDebugInfoFromCommandResult(getResultWithOutput())); + } + + if (testResult == null) { throw new Error( - 'Failed to parse test results from RN tester binary result.\n' + + 'Failed to find test results in RN tester binary output.\n' + getDebugInfoFromCommandResult(result), ); } - return {logs: outputArray.join('\n'), testResult}; + return testResult; } function generateBytecodeBundle({ @@ -77,7 +130,7 @@ function generateBytecodeBundle({ bytecodePath: string, isOptimizedMode: boolean, }): void { - const hermesCompilerCommandResult = runBuck2( + const hermesCompilerCommandResult = runBuck2Sync( [ 'run', ...getBuckModesForPlatform(isOptimizedMode), @@ -180,36 +233,33 @@ module.exports = async function runTest( }); } - const rnTesterCommandResult = runBuck2([ - 'run', - ...getBuckModesForPlatform( - testConfig.mode === FantomTestConfigMode.Optimized, - ), - '//xplat/ReactNative/react-native-cxx/samples/tester:tester', - '--', - '--bundlePath', - testConfig.mode === FantomTestConfigMode.DevelopmentWithSource - ? testJSBundlePath - : testBytecodeBundlePath, - '--featureFlags', - JSON.stringify(testConfig.flags.common), - '--minLogLevel', - PRINT_FANTOM_OUTPUT ? 'info' : 'error', - ]); - - if (rnTesterCommandResult.status !== 0) { - throw new Error(getDebugInfoFromCommandResult(rnTesterCommandResult)); - } - - if (PRINT_FANTOM_OUTPUT) { - console.log(getDebugInfoFromCommandResult(rnTesterCommandResult)); - } + const rnTesterCommandResult = runBuck2( + [ + 'run', + ...getBuckModesForPlatform( + testConfig.mode === FantomTestConfigMode.Optimized, + ), + '//xplat/ReactNative/react-native-cxx/samples/tester:tester', + '--', + '--bundlePath', + testConfig.mode === FantomTestConfigMode.DevelopmentWithSource + ? testJSBundlePath + : testBytecodeBundlePath, + '--featureFlags', + JSON.stringify(testConfig.flags.common), + '--minLogLevel', + EnvironmentOptions.printCLIOutput ? 'info' : 'error', + ], + { + withFDB: EnvironmentOptions.enableCppDebugging, + }, + ); - const rnTesterParsedOutput = parseRNTesterCommandResult( + const processedResult = await processRNTesterCommandResult( rnTesterCommandResult, ); - const testResultError = rnTesterParsedOutput.testResult.error; + const testResultError = processedResult.error; if (testResultError) { const error = new Error(testResultError.message); error.stack = symbolicateStackTrace(sourceMapPath, testResultError.stack); @@ -218,12 +268,8 @@ module.exports = async function runTest( const endTime = Date.now(); - if (process.env.SANDCASTLE == null) { - console.log(rnTesterParsedOutput.logs); - } - const testResults = - nullthrows(rnTesterParsedOutput.testResult.testResults).map(testResult => ({ + nullthrows(processedResult.testResults).map(testResult => ({ ancestorTitles: [] as Array, failureDetails: [] as Array, testFilePath: testPath, @@ -233,9 +279,9 @@ module.exports = async function runTest( ), })) ?? []; - const snapshotResults = nullthrows( - rnTesterParsedOutput.testResult.testResults, - ).map(testResult => testResult.snapshotResults); + const snapshotResults = nullthrows(processedResult.testResults).map( + testResult => testResult.snapshotResults, + ); const snapshotResult = updateSnapshotsAndGetJestSnapshotResult( snapshotState, diff --git a/packages/react-native-fantom/runner/utils.js b/packages/react-native-fantom/runner/utils.js index d5aa6deeac7a..93873737d3f0 100644 --- a/packages/react-native-fantom/runner/utils.js +++ b/packages/react-native-fantom/runner/utils.js @@ -9,7 +9,8 @@ * @oncall react_native */ -import {spawnSync} from 'child_process'; +import * as EnvironmentOptions from './EnvironmentOptions'; +import {spawn, spawnSync} from 'child_process'; import crypto from 'crypto'; import fs from 'fs'; import os from 'os'; @@ -44,24 +45,80 @@ export function getBuckModesForPlatform( return ['@//xplat/mode/react-force-cxx-platform', osPlatform]; } -type SpawnResultWithOriginalCommand = { - ...ReturnType, +export type AsyncCommandResult = { originalCommand: string, - ... + childProcess: ReturnType, + done: Promise, + pid: number, + status: ?number, + signal: ?string, + error: ?Error, + stdout: ?string, + stderr: ?string, }; -export function runBuck2(args: Array): SpawnResultWithOriginalCommand { - // If these tests are already running from withing a buck2 process, e.g. when - // they are scheduled by a `buck2 test` wrapper, calling `buck2` again would - // cause a daemon-level deadlock. - // To prevent this - explicitly pass custom `--isolation-dir`. Reuse the same - // dir across tests (even running in different jest processes) to properly - // employ caching. - if (process.env.BUCK2_WRAPPER != null) { - args.unshift('--isolation-dir', BUCK_ISOLATION_DIR); +export type SyncCommandResult = { + originalCommand: string, + pid: number, + status: number, + signal: ?string, + error: ?Error, + stdout: string, + stderr: string, +}; + +function maybeLogCommand(command: string, args: Array): void { + if (EnvironmentOptions.logCommands) { + console.log(`RUNNING \`${command} ${args.join(' ')}\``); } +} - const result = spawnSync('buck2', args, { +export function runCommand( + command: string, + args: Array, +): AsyncCommandResult { + maybeLogCommand(command, args); + + const childProcess = spawn(command, args, { + encoding: 'utf8', + env: { + ...process.env, + PATH: `/usr/local/bin:${process.env.PATH ?? ''}`, + }, + }); + + const result: AsyncCommandResult = { + childProcess, + done: new Promise(resolve => { + childProcess.on('close', (code: number, signal: string) => { + result.status = code; + result.signal = signal; + resolve(result); + }); + }), + originalCommand: `${command} ${args.join(' ')}`, + pid: childProcess.pid, + status: null, + signal: null, + error: null, + stdout: null, + stderr: null, + }; + + childProcess.on('error', error => { + result.error = error; + }); + + return result; +} + +export function runCommandSync( + command: string, + args: Array, +): SyncCommandResult { + maybeLogCommand(command, args); + + const result = spawnSync(command, args, { encoding: 'utf8', env: { ...process.env, @@ -70,28 +127,35 @@ export function runBuck2(args: Array): SpawnResultWithOriginalCommand { }); return { - ...result, - originalCommand: `buck2 ${args.join(' ')}`, + originalCommand: `${command} ${args.join(' ')}`, + pid: result.pid, + status: result.status, + signal: result.signal, + error: result.error, + stdout: result.stdout.toString(), + stderr: result.stderr.toString(), }; } export function getDebugInfoFromCommandResult( - commandResult: SpawnResultWithOriginalCommand, + commandResult: SyncCommandResult | AsyncCommandResult, ): string { const maybeSignal = commandResult.signal != null ? `, signal: ${commandResult.signal}` : ''; const resultByStatus = commandResult.status === 0 ? 'succeeded' - : `failed (status code: ${commandResult.status}${maybeSignal})`; + : `failed (status code: ${commandResult.status ?? '(empty)'}${maybeSignal})`; const logLines = [ `Command ${resultByStatus}: ${commandResult.originalCommand}`, '', 'stdout:', + // $FlowExpectedError[sketchy-null-string] commandResult.stdout || '(empty)', '', 'stderr:', + // $FlowExpectedError[sketchy-null-string] commandResult.stderr || '(empty)', ]; @@ -102,6 +166,56 @@ export function getDebugInfoFromCommandResult( return logLines.join('\n'); } +function getCommandAndArgsWithFDB( + command: string, + args: Array, + useFDB: boolean, +) { + if (useFDB) { + return ['fdb', [command].concat(args)]; + } else { + return [command, args]; + } +} + +export function runBuck2( + args: Array, + options?: {withFDB: boolean}, +): AsyncCommandResult { + const [actualCommand, actualArgs] = getCommandAndArgsWithFDB( + 'buck2', + processArgsForBuck(args), + options?.withFDB ?? false, + ); + return runCommand(actualCommand, actualArgs); +} + +export function runBuck2Sync( + args: Array, + options?: {withFDB: boolean}, +): SyncCommandResult { + const [actualCommand, actualArgs] = getCommandAndArgsWithFDB( + 'buck2', + processArgsForBuck(args), + options?.withFDB ?? false, + ); + return runCommandSync(actualCommand, actualArgs); +} + +function processArgsForBuck(args: Array): Array { + // If these tests are already running from withing a buck2 process, e.g. when + // they are scheduled by a `buck2 test` wrapper, calling `buck2` again would + // cause a daemon-level deadlock. + // To prevent this - explicitly pass custom `--isolation-dir`. Reuse the same + // dir across tests (even running in different jest processes) to properly + // employ caching. + if (process.env.BUCK2_WRAPPER != null) { + return ['--isolation-dir', BUCK_ISOLATION_DIR].concat(args); + } + + return args; +} + export function getShortHash(contents: string): string { return crypto.createHash('md5').update(contents).digest('hex').slice(0, 8); } @@ -134,3 +248,31 @@ export function symbolicateStackTrace( }) .join('\n'); } + +export type ConsoleLogMessage = { + type: 'console-log', + level: 'info' | 'warn' | 'error', + message: string, +}; + +export function printConsoleLog(log: ConsoleLogMessage): void { + if (process.env.SANDCASTLE != null) { + return; + } + + switch (log.type) { + case 'console-log': + switch (log.level) { + case 'info': + console.log(log.message); + break; + case 'warn': + console.warn(log.message); + break; + case 'error': + console.error(log.message); + break; + } + break; + } +} diff --git a/packages/react-native-fantom/runner/warmup/warmup.js b/packages/react-native-fantom/runner/warmup/warmup.js index a5503c154ad0..93a918e09446 100644 --- a/packages/react-native-fantom/runner/warmup/warmup.js +++ b/packages/react-native-fantom/runner/warmup/warmup.js @@ -12,7 +12,7 @@ import { getBuckModesForPlatform, getDebugInfoFromCommandResult, - runBuck2, + runBuck2Sync, } from '../utils'; // $FlowExpectedError[untyped-import] import fs from 'fs'; @@ -94,7 +94,7 @@ async function warmUpMetro(isOptimizedMode: boolean): Promise { } function warmUpHermesCompiler(isOptimizedMode: boolean): void { - const buildHermesCompilerCommandResult = runBuck2([ + const buildHermesCompilerCommandResult = runBuck2Sync([ 'build', ...getBuckModesForPlatform(isOptimizedMode), '//xplat/hermes/tools/hermesc:hermesc', @@ -108,7 +108,7 @@ function warmUpHermesCompiler(isOptimizedMode: boolean): void { } function warmUpRNTesterCLI(isOptimizedMode: boolean): void { - const buildRNTesterCommandResult = runBuck2([ + const buildRNTesterCommandResult = runBuck2Sync([ 'build', ...getBuckModesForPlatform(isOptimizedMode), '//xplat/ReactNative/react-native-cxx/samples/tester:tester', diff --git a/packages/react-native-fantom/runtime/setup.js b/packages/react-native-fantom/runtime/setup.js index 31055e4a9d4a..740f6e20288e 100644 --- a/packages/react-native-fantom/runtime/setup.js +++ b/packages/react-native-fantom/runtime/setup.js @@ -15,6 +15,7 @@ import expect from './expect'; import {createMockFunction} from './mocks'; import {setupSnapshotConfig, snapshotContext} from './snapshotContext'; import nullthrows from 'nullthrows'; +import NativeFantom from 'react-native/src/private/specs/modules/NativeFantom'; export type TestCaseResult = { ancestorTitles: Array, @@ -190,7 +191,12 @@ function executeTests() { } function reportTestSuiteResult(testSuiteResult: TestSuiteResult): void { - console.log(JSON.stringify(testSuiteResult)); + NativeFantom.reportTestSuiteResultsJSON( + JSON.stringify({ + type: 'test-result', + ...testSuiteResult, + }), + ); } global.$$RunTests$$ = () => { diff --git a/packages/react-native-fantom/src/__tests__/Fantom-itest.js b/packages/react-native-fantom/src/__tests__/Fantom-itest.js index f16d30bd10fb..250c31d4d828 100644 --- a/packages/react-native-fantom/src/__tests__/Fantom-itest.js +++ b/packages/react-native-fantom/src/__tests__/Fantom-itest.js @@ -76,28 +76,30 @@ describe('Fantom', () => { // TODO: when error handling is fixed, this should verify using `toThrow` it('should throw when running a task inside another task', () => { - let lastCallbackExecuted = 0; + let threw = false; + runTask(() => { - lastCallbackExecuted = 1; - runTask(() => { - lastCallbackExecuted = 2; - throw new Error('Recursive runTask should be unreachable'); - }); + // TODO replace with expect(() => { ... }).toThrow() when error handling is fixed + try { + runTask(() => {}); + } catch { + threw = true; + } }); - expect(lastCallbackExecuted).toBe(1); + expect(threw).toBe(true); + + threw = false; runTask(() => { queueMicrotask(() => { - lastCallbackExecuted = 3; - runTask(() => { - lastCallbackExecuted = 4; - throw new Error( - 'Recursive runTask from micro-task should be unreachable', - ); - }); + try { + runTask(() => {}); + } catch { + threw = true; + } }); }); - expect(lastCallbackExecuted).toBe(3); + expect(threw).toBe(true); }); }); @@ -125,16 +127,24 @@ describe('Fantom', () => { runTask(() => { root.render( <> - - + + , ); }); expect(root.getRenderedOutput().toJSX()).toEqual( <> - - + + , ); @@ -233,18 +243,26 @@ describe('Fantom', () => { runTask(() => { root.render( <> - - hello world! - + + hello world! + , ); }); expect(root.getRenderedOutput({props: []}).toJSX()).toEqual( <> - - hello world! - + + hello world! + , ); diff --git a/packages/react-native-fantom/src/getFantomRenderedOutput.js b/packages/react-native-fantom/src/getFantomRenderedOutput.js index 496a462a3d32..ede6e38285fb 100644 --- a/packages/react-native-fantom/src/getFantomRenderedOutput.js +++ b/packages/react-native-fantom/src/getFantomRenderedOutput.js @@ -9,10 +9,10 @@ * @oncall react_native */ -import FantomModule from './specs/NativeFantomModule'; // $FlowExpectedError[untyped-import] import micromatch from 'micromatch'; import * as React from 'react'; +import NativeFantom from 'react-native/src/private/specs/modules/NativeFantom'; export type RenderOutputConfig = { ...FantomRenderedOutputConfig, @@ -114,7 +114,7 @@ export default function getFantomRenderedOutput( } = config; return new FantomRenderedOutput( JSON.parse( - FantomModule.getRenderedOutput(surfaceId, { + NativeFantom.getRenderedOutput(surfaceId, { includeRoot, includeLayoutMetrics, }), @@ -152,16 +152,20 @@ function convertRawJsonToJSX( function createJSXElementForTestComparison( type: string, props: mixed, + key?: ?string, ): React.Node { const Tag = type; - return ; + return ; } function rnTypeToTestType(type: string): string { return `rn-${type.substring(0, 1).toLowerCase() + type.substring(1)}`; } -function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node { +function jsonChildToJSXChild( + jsonChild: FantomJsonObject | string, + index?: ?number, +): React.Node { if (typeof jsonChild === 'string') { return jsonChild; } else { @@ -172,6 +176,7 @@ function jsonChildToJSXChild(jsonChild: FantomJsonObject | string): React.Node { jsxChildren == null ? jsonChild.props : {...jsonChild.props, children: jsxChildren}, + index != null ? String(index) : undefined, ); } } @@ -184,7 +189,7 @@ function jsonChildrenToJSXChildren(jsonChildren: FantomJsonObject['children']) { let allJSXChildrenAreStrings = true; let jsxChildrenString = ''; for (let i = 0; i < jsonChildren.length; i++) { - const jsxChild = jsonChildToJSXChild(jsonChildren[i]); + const jsxChild = jsonChildToJSXChild(jsonChildren[i], i); jsxChildren.push(jsxChild); if (allJSXChildrenAreStrings) { if (typeof jsxChild === 'string') { diff --git a/packages/react-native-fantom/src/index.js b/packages/react-native-fantom/src/index.js index b765810f66a0..67795cc5c67f 100644 --- a/packages/react-native-fantom/src/index.js +++ b/packages/react-native-fantom/src/index.js @@ -15,8 +15,8 @@ import type { import type {MixedElement} from 'react'; import getFantomRenderedOutput from './getFantomRenderedOutput'; -import FantomModule from './specs/NativeFantomModule'; import ReactFabric from 'react-native/Libraries/Renderer/shims/ReactFabric'; +import NativeFantom from 'react-native/src/private/specs/modules/NativeFantom'; let globalSurfaceIdCounter = 1; @@ -35,7 +35,7 @@ class Root { render(element: MixedElement) { if (!this.#hasRendered) { - FantomModule.startSurface(this.#surfaceId); + NativeFantom.startSurface(this.#surfaceId); this.#hasRendered = true; } @@ -43,13 +43,13 @@ class Root { } getMountingLogs(): Array { - return FantomModule.getMountingManagerLogs(this.#surfaceId); + return NativeFantom.getMountingManagerLogs(this.#surfaceId); } destroy() { // TODO: check for leaks. - FantomModule.stopSurface(this.#surfaceId); - FantomModule.flushMessageQueue(); + NativeFantom.stopSurface(this.#surfaceId); + NativeFantom.flushMessageQueue(); } getRenderedOutput(config: RenderOutputConfig = {}): FantomRenderedOutput { @@ -100,7 +100,7 @@ export function runWorkLoop(): void { try { flushingQueue = true; - FantomModule.flushMessageQueue(); + NativeFantom.flushMessageQueue(); } finally { flushingQueue = false; } diff --git a/packages/react-native-fantom/src/specs/NativeFantomModule.js b/packages/react-native/src/private/specs/modules/NativeFantom.js similarity index 65% rename from packages/react-native-fantom/src/specs/NativeFantomModule.js rename to packages/react-native/src/private/specs/modules/NativeFantom.js index da67f38a1e75..57e8f7fda028 100644 --- a/packages/react-native-fantom/src/specs/NativeFantomModule.js +++ b/packages/react-native/src/private/specs/modules/NativeFantom.js @@ -4,13 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ -import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport'; +import type {TurboModule} from '../../../../Libraries/TurboModule/RCTExport'; -import {TurboModuleRegistry} from 'react-native'; +import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboModuleRegistry'; // match RenderFormatOptions.h export type RenderFormatOptions = { @@ -24,6 +24,9 @@ interface Spec extends TurboModule { getMountingManagerLogs: (surfaceId: number) => Array; flushMessageQueue: () => void; getRenderedOutput: (surfaceId: number, config: RenderFormatOptions) => string; + reportTestSuiteResultsJSON: (results: string) => void; } -export default TurboModuleRegistry.getEnforcing('Fantom') as Spec; +export default TurboModuleRegistry.getEnforcing( + 'NativeFantomCxx', +) as Spec; diff --git a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js index a7ea8e84e8dd..8ad459de8af1 100644 --- a/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js +++ b/packages/react-native/src/private/webapis/intersectionobserver/__tests__/IntersectionObserver-itest.js @@ -487,7 +487,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -549,7 +548,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -610,7 +608,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -942,7 +939,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -1003,7 +999,6 @@ describe('IntersectionObserver', () => { maybeNode = receivedNode; }} /> - , , ); }); @@ -1314,13 +1309,9 @@ describe('IntersectionObserver', () => { }); expect(node.isConnected).toBe(false); - Fantom.runTask(() => { - observer = new IntersectionObserver(() => {}); - observer.observe(node); - // TODO what happens if this throws an exception? - observer.unobserve(node); - throw new Error('unobserve should not throw'); - }); + observer = new IntersectionObserver(() => {}); + observer.observe(node); + observer.unobserve(node); }); it('should not report the initial state if the target is unobserved before it is delivered', () => { @@ -1497,19 +1488,16 @@ describe('IntersectionObserver', () => { const node = ensureReactNativeElement(maybeNode); - Fantom.runTask(() => { - observer1 = new IntersectionObserver(() => {}); - observer2 = new IntersectionObserver(() => {}); + 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); - throw new Error('unobserve should not throw'); - }); + // The second call shouldn't log errors (that would make the test fail). + observer2.unobserve(node); }); }); diff --git a/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js b/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js index 25801da127c9..8163f88a15a5 100644 --- a/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js +++ b/packages/react-native/src/private/webapis/mutationobserver/__tests__/MutationObserver-itest.js @@ -383,14 +383,14 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }}> , ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -968,13 +968,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -1016,13 +1016,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); const observerCallback = jest.fn(); const observer = new MutationObserver(observerCallback); @@ -1048,13 +1048,13 @@ describe('MutationObserver', () => { { - maybeObservedNode = ensureReactNativeElement(receivedNode); + maybeObservedNode = receivedNode; }} />, ); }); - const observedNode = nullthrows(maybeObservedNode); + const observedNode = ensureReactNativeElement(maybeObservedNode); Fantom.runTask(() => { root.render(<>);