Commit Graph

40 Commits

Author SHA1 Message Date
Rubén Norte 7f985f29e3 Add tests for console.table (#48589)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48589

Changelog: [internal]

Added basic tests for the current implementation of the `console.table` polyfill (not the CDP implementation).

Reviewed By: sammy-SC

Differential Revision: D67791579

fbshipit-source-id: 80d64903a92e87e0724ed302ec0521419f45f9a7
2025-01-10 05:41:37 -08:00
Rubén Norte 8310d651e0 Mark benchmark API as unstable (#48570)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48570

Changelog: [internal]

We're still iterating on this feature and making sure it reports stable results, so marking it as `unstable` to set expectations.

Reviewed By: andrewdacenko

Differential Revision: D67975844

fbshipit-source-id: 41e93cb9cb0c887a96178e4a4d5078d1899b2478
2025-01-09 10:11:18 -08:00
Rubén Norte ff7c550a86 Run benchmarks in test mode when not specifying verification functions in CI (#48451)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48451

Changelog: [internal]

Modifies the execution of benchmarks in CI to run benchmarks in test mode when they don't define a `verify` method.

If a benchmark uses `verify`, the test is meant to make sure that the benchmark doesn't regress in CI. If it doesn't, then running the benchmark on CI doesn't provide much value. In that case, we run a single iteration of each test case just to make sure things don't break over time.

Reviewed By: rshest

Differential Revision: D67637754

fbshipit-source-id: 33b78a9c809386cf2e040314b0427de6a53da3e3
2025-01-06 07:10:28 -08:00
Rubén Norte 3795f0fb66 Add API to run benchmarks in Fantom (#48452)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48452

Changelog: [internal]

Implements a basic API to run benchmarks with Fantom (using `tinybench` under the hood):

```
import {benchmark} from 'react-native/fantom';

benchmark
  .suite('Suite name', {
    // options
  })
  .add(
    'Test name',
    () => {
      // code to benchmark
    },
    {
      beforeAll: () => {},
      beforeEach: () => {},
      afterEach: () => {},
      afterAll: () => {},
    },
  )
  .verify(results => {
    // check results and throw an error if the expectations fail
  });
```

Features:
* Print benchmark results in the console as a table.
* It opts into optimized builds automatically
* Verifies that optimized build is used (unless manually opting out of the check via `disableOptimizedBuildCheck`).
* Supports verification of results (making expectations and making the test fail if the benchmark doesn't meet some expectations).

Reviewed By: rshest

Differential Revision: D66926183

fbshipit-source-id: 61cfa7689ea7684eb870fbbc815b8d236a1871e6
2025-01-06 07:10:28 -08:00
Rubén Norte a1b13f6a55 Extract ensureInstance utility from tests (#48434)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48434

Changelog: [internal]

We were starting to repeat this logic too much in tests, so extracting so we can reuse it.

Reviewed By: rshest

Differential Revision: D67520443

fbshipit-source-id: 64e4e5b35f83dc45e41bb0efae9685aeaf0cf2e2
2025-01-03 12:57:16 -08:00
Rubén Norte 6c383ea7b8 Set more sensible defaults for viewport width and height (#48436)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48436

Changelog: [internal]

Changing the defaults to use something that resembles a real device (in this case the iPhone 14 which is a very common device).

Reviewed By: christophpurrer

Differential Revision: D67759914

fbshipit-source-id: 87fe3be19196ece62c412e5076c601be746a4f22
2025-01-03 12:57:16 -08:00
Rubén Norte bac56bf828 Allow configuring viewport width, height and device pixel ratio (#48433)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48433

Changelog: [internal]

Allows customizing the root dimensions.

Reviewed By: christophpurrer

Differential Revision: D67693031

fbshipit-source-id: ddbe426a6492512dc2eb7554f26b63d14d5ce75d
2025-01-03 12:57:16 -08:00
Rubén Norte 39757da650 Add environment variable to enable C++ debugging (#48441)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48441

Changelog: [internal]

Adds a new environment variable (`FANTOM_ENABLE_CPP_DEBUGGING`) to enable C++ debugging via `fdb`.

Reviewed By: RSNara

Differential Revision: D67683048

fbshipit-source-id: d074a1a063c5da6b048d5456036e83cc14245eaf
2025-01-03 04:57:43 -08:00
Rubén Norte d28300ad9d Add environment variables to print Fantom output and buck commands (#48440)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48440

Changelog: [internal]

Modifies the Fantom runner to read 2 new environment variables to help with debugging:
- `FANTOM_PRINT_OUTPUT`: prints the output of the CLI to the output of the test.
- `FANTOM_LOG_COMMANDS`: logs the buck commands executed by the runner, so they can be re-run outside the runner for debugging, etc.

Reviewed By: rshest

Differential Revision: D67682750

fbshipit-source-id: aff48c4f47078db1be53e0ee105089fbc921768f
2025-01-03 04:57:43 -08:00
Rubén Norte 42b911b5cb Implement streaming mode for console logs in tests (#48372)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48372

Changelog: [internal]

Implements log streaming in Fantom tests. This allows us to see the logs emitted from tests as they're logged, so we don't need to wait until the test completes to flush all of them at the same time.

Reviewed By: rshest

Differential Revision: D67600609

fbshipit-source-id: efb3125e13fd9aec1800a5f1ddaf0d93dcb29218
2025-01-03 04:57:43 -08:00
Rubén Norte f1ba4ef131 Add async flavors for runCommand and runBuck2 utilities (#48371)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48371

Changelog: [internal]

Adds a new favor for `runCommand` and `runBuck2` that works asynchronously and support parsing their output in real time.

Reviewed By: javache

Differential Revision: D67600614

fbshipit-source-id: 99dd2ce9bff11036829f214bf19208b10c9c1b25
2025-01-03 04:57:43 -08:00
Rubén Norte 8f096ab4f8 Refactor utility to run buck2 commands as a method to run arbitrary commands (#48370)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48370

Changelog: [internal]

Small refactor in preparation for async commands with streaming.

Reviewed By: javache

Differential Revision: D67600611

fbshipit-source-id: 11fe6b6ccd8849f904338ccc9454361ad5923863
2025-01-03 04:57:43 -08:00
Rubén Norte 726a72328e Use structured output for Fantom logs and test results (#48369)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48369

Changelog: [internal]

This improves logs in Fantom by preserving the original log levels. It's also in preparation for adding support for log streaming in tests.

Reviewed By: javache

Differential Revision: D67600616

fbshipit-source-id: 1c4997d5e836a78327f33092527543fe025c90c6
2025-01-03 04:57:43 -08:00
Rubén Norte 5f09c36942 Remove unnecessary filter for AppRegistry logs (#48367)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48367

Changelog: [internal]

We removed the calls to `AppRegistry` in Fantom, so this filter isn't necessary anymore (just a no-op).

Reviewed By: rshest

Differential Revision: D67600610

fbshipit-source-id: d985cc5f0ee1728ac72c567bc091a6c2877f2659
2025-01-03 04:57:43 -08:00
Rubén Norte fb3b87c2b5 Remove existing logs and warnings from tests (#48391)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48391

Changelog: [internal]

When we enabled log streaming in Fantom, we saw a lot of logs that we were previously not forwarding (console.error, console.warn) in existing tests.

This removes all the warnings and errors from those tests.

Reviewed By: rshest

Differential Revision: D67602299

fbshipit-source-id: 111f373eafd8707f2746ff727894f1fa4283b83f
2025-01-03 04:57:43 -08:00
Rubén Norte d7d9e1c090 Use codegen for Fantom native module (#48432)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48432

Changelog: [internal]

This moves the native module definition for Fantom to the `react-native` package so we can migrate the module to use the codegen.

Also implements the migration.

Reviewed By: christophpurrer

Differential Revision: D67759729

fbshipit-source-id: d79d078908b05fc4b6f5f26f0144ab7e3485cb83
2025-01-03 04:57:43 -08:00
Rubén Norte c0f3e64070 Follow naming convention for NativeFantom module (#48368)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48368

Changelog: [internal]

Just a minor rename to align with the existing convention.

Reviewed By: javache

Differential Revision: D67549203

fbshipit-source-id: faa9e34cdce7c59e2c6b3f7e697c90df103699d0
2025-01-03 04:57:43 -08:00
Rubén Norte f20486cc77 Improve error messages in expect().toThrow(message) (#48430)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48430

Changelog: [internal]

This expectation currently prints a very generic message that is hard to parse, so this change improves it a bit to account for more cases. E.g.:
* Before: "Expected <function> to throw"
* After: "Expected <function> to throw with message 'foo', but threw with message 'bar'"

Reviewed By: rshest

Differential Revision: D67738146

fbshipit-source-id: 690f15971cec0e8a7b038eeacc9302c9f3edc323
2025-01-03 02:16:38 -08:00
Mitya Kononchuk 8696b79f73 Fix running fantom tests with high parallelism (#48307)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48307

Changelog:
[General][Fixed] - Fix a bug when fantom tests could not be run in parallel, e.g. in a stress-test.

Reviewed By: rubennorte, danalex97

Differential Revision: D67334828

fbshipit-source-id: 3db18f6a100925480dbf8385f9ea414187406f4a
2024-12-17 10:07:26 -08:00
Rubén Norte 06584241ba Fix ESLint warnings and remove from ignore list (#48291)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48291

Changelog: [internal]

`react-native-fantom` was added to `.eslintignore` when we upgraded to React 19 because we wanted to reduce the amount of warnings to ease the migration.

This re-enables ESLint for that directory and removes the warnings.

Reviewed By: cipolleschi

Differential Revision: D67283104

fbshipit-source-id: 4ec2363ceaff3cd7bd6e5d70e9588c3dd22d7d85
2024-12-16 09:19:55 -08:00
Rubén Norte 18243d07e4 Customize log level in Fantom output (#48263)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48263

Changelog: [internal]

Customize log level in Fantom based on flag in runner.js.

Reviewed By: javache

Differential Revision: D67199970

fbshipit-source-id: 31cdd2eaeee8e7ab4c8985661b35822d78d0457b
2024-12-16 06:03:03 -08:00
Rubén Norte 358fd38825 Add scheduleTask and runWorkLoop to public API (#48284)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48284

Changelog: [internal]

We recently prevented tasks that run via `runTask` to synchronously call `runTask` because the execution is synchronous and we can't nest tasks in the event loop (D67107664 / https://github.com/facebook/react-native/pull/48235).

This adds `scheduleTask` to schedule tasks (also within tasks) with the right expectations (the task will not run synchronously on that call but at the right time).

It also adds `runWorkLoop` so we can run scheduled tasks if they're not scheduled from an already running task.

Reviewed By: javache

Differential Revision: D67275518

fbshipit-source-id: acde0093802fbcb7083334f2c0247b37b759a6b1
2024-12-16 04:50:15 -08:00
Pieter De Baets 5edd32bf3f Fix MacOS build (#48285)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48285

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D67275514

fbshipit-source-id: 6512cbb090e90f827f643353a0a73c4f9516f651
2024-12-16 04:06:27 -08:00
Pieter De Baets ba8136e41d Create TurboModule for test helpers (#48283)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48283

Migrate from custom JSI integration to use TurboModule base-class.

This doesn't use codegen right now for ease of migration, and to avoid needing to setup a js_library buck definition for react-native-fantom. We should also figure out what the right abstraction/division of responsibilities is going forward for TesterAppDelegate and FantomModule.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D67111850

fbshipit-source-id: e1623d80f1f25ec123315b3620930dd17dd8a8a7
2024-12-16 04:06:27 -08:00
Rubén Norte edb3850adb Log status code when commands fail (#48222)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48222

Changelog: [internal]

Tiny improvement over the current setup so it might help detect some current issues.

Reviewed By: yungsters

Differential Revision: D67021976

fbshipit-source-id: 7829f2ea0d839178f1a50d176b42dc0906c2e585
2024-12-13 08:10:59 -08:00
Pieter De Baets c06f13e7fb Error when using runTask in a re-entrant way (#48235)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48235

Recursively calling runTask is not supported, as the inner call will no-op since we're already executing the eventloop.

Currently errors are not correctly propagated, but this at least makes it so that we don't attempt to schedule the task either, which could lead to incorrect assumptions being made.

Changelog: [internal]

Reviewed By: rubennorte

Differential Revision: D67107664

fbshipit-source-id: e665a96671f4812308d87aec3b880ce2009328e2
2024-12-12 08:09:02 -08:00
Mitya Kononchuk 477489ce84 Fix running fantom tests via buck-test (#48215)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48215

Changelog: [internal]

Reviewed By: rubennorte

Differential Revision: D66976980

fbshipit-source-id: d553c2f702d6928fb0ad88fcc2c6f04160a65d02
2024-12-11 07:07:10 -08:00
Andrew Datsenko a298ccabe2 Add snapshot update / delete capability (#48096)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48096

Changelog: [Internal]

Managing snapshot state internally by adding / updating snapshot data.

Reviewed By: christophpurrer

Differential Revision: D66707175

fbshipit-source-id: 0366d834eafa0ca702f03de0210392181fd90a58
2024-12-09 19:09:57 -08:00
Andrew Datsenko a8a136f3ef Add .toMatchSnapshot() (#48029)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48029

Changelog: [Internal]

Adding snapshot support for rendered output only for now.
This will only work if snapshot is created beforehand by hand.

# Next steps
* Create snapshot when no prior snapshot is available
* Pass and update if instructed

Reviewed By: christophpurrer

Differential Revision: D66601387

fbshipit-source-id: fe528cded43c5ba36d314bd9af8e3fb84b98ac3e
2024-12-09 19:09:57 -08:00
Andrew Datsenko a4a2c2867a Add jest-snapshot (#48095)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48095

Changelog: [Internal]
Add `jest-snapshot` `v29.7.0`

Reviewed By: christophpurrer

Differential Revision: D66714069

fbshipit-source-id: 783584519e95b337d36c4a00610bcd970a041d4d
2024-12-09 19:09:57 -08:00
Rubén Norte 3cc67fed36 Add Fantom mode for development with Hermes bytecode (#48178)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48178

Changelog: [internal]

Adds a new mode for Fantom to run tests with dev-mode bytecode. Right now the modes were only dev (development with source code) or opt (optimized bytecode).

Reviewed By: rshest

Differential Revision: D66888986

fbshipit-source-id: 34b2566a65d138790e16f8fb5787fd9c2bcde536
2024-12-09 05:43:27 -08:00
Rubén Norte 4d07fb7662 Use enum for Fantom modes (#48179)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48179

Changelog: [internal]

Migrating this type to an enum, which is safer, because it prevents errors like:

```
// when it's actually 'dev'
if (mode === 'development') {

}
```

Reviewed By: rshest

Differential Revision: D66888985

fbshipit-source-id: 4f3f91fad6ca5256baa2123425b2bad11fe036f9
2024-12-09 05:43:27 -08:00
Rubén Norte 07a7b63fdd Only prewarm in CI (#48151)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48151

Changelog: [internal]

We have global setup step in Fantom to prewarm caches to properly attribute test running time, but this isn't necessary when running tests locally. Attribution isn't as important there. This disables the prewarming step so we can run individual tests as fast as we can.

Reviewed By: sammy-SC

Differential Revision: D66877990

fbshipit-source-id: 1f33c19a3c537c1c0e499fd7a6c405450cb9f86d
2024-12-09 05:43:27 -08:00
Rubén Norte 82abba9936 Implement warmup for optimized mode (#48150)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48150

Changelog: [internal]

We're starting to have some Fantom tests that run in optimized mode, but we're not currently prewarming for that case. This adds that capability to do proper attribution of run time for tests.

Reviewed By: javache

Differential Revision: D66877991

fbshipit-source-id: dccb80cd6a4f664de7df0661456bad78d960826d
2024-12-09 05:43:27 -08:00
Rubén Norte 47589f53b1 Add tests for Fantom modes (#48123)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48123

Changelog: [internal]

This verifies that the modes specified in the pragmas are applied correctly.

Reviewed By: andrewdacenko

Differential Revision: D66822377

fbshipit-source-id: 420f21f171c5d356ab91b49f7a33345386f6f0c0
2024-12-09 05:43:27 -08:00
Rubén Norte 81fbd18410 Move remaining Fantom files to react-native-fantom (#48143)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48143

Changelog: [internal]

Just a small cleanup to move `jest/integration/*` to `packages/react-native-fantom`, so everything related to Fantom (config, runner, runtime, etc.) is in the same directory.

Reviewed By: javache

Differential Revision: D66874763

fbshipit-source-id: 8b87d7320c7704f7ce6cd58761508193784f5ce2
2024-12-06 05:24:31 -08:00
Rubén Norte 923b194e47 Rename ReactNativeTester as just Fantom (#48142)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48142

Changelog: [internal]

This is the default export from the `react-native/fantom` package and it makes sense to be called that way. Also, this is similar to the `jest` global.

Reviewed By: javache

Differential Revision: D66874225

fbshipit-source-id: 8b43a637ebb42b5b1acb9ea5a6dbedd4c1a4f9e0
2024-12-06 05:24:31 -08:00
Rubén Norte 3fafc9f9cf Rename FantomRenderedOutput as getFantomRenderedOutput to follow convention (#48141)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48141

Changelog: [internal]

This just aligns the file name with the common convention to name modules with the same name as their default export (if any).

Reviewed By: javache

Differential Revision: D66874227

fbshipit-source-id: 2a619b434c26a29f1774cba1c32ba711b1a7af46
2024-12-06 05:24:31 -08:00
Rubén Norte ba8d184b77 Move render output tests to ReactNativeTester (#48140)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48140

Changelog: [internal]

These tests test an API that's part of `ReactNativeTester` (will be renamed as `Fantom`) so it makes sense that they're in the same test file as the tests for the rest of the API.

Reviewed By: javache

Differential Revision: D66874226

fbshipit-source-id: f17e14c83cb5ca95ac619c5398c49ad84a27cfa5
2024-12-06 05:24:31 -08:00
Rubén Norte b253b0fe94 Create @react-native/fantom package (#48125)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48125

Changelog: [internal]

This just moves the runtime modules for Fantom to its own package.

Reviewed By: javache

Differential Revision: D66825478

fbshipit-source-id: ac4dbc23b86895f09abc46345d497c1c53737ae2
2024-12-06 05:24:31 -08:00