Commit Graph

271 Commits

Author SHA1 Message Date
Rubén Norte
9f604dbd43 Watch changes in C++ files (#47871)
Some checks are pending
Label closed PR as merged and leave a comment / comment-and-label (push) Waiting to run
Publish Bumped Packages / publish_bumped_packages (push) Waiting to run
Update node modules cache / update_node_modules_cache (push) Waiting to run
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47871

Changelog: [internal]

No need to keep going back to save test files when we change C++ files and need to re-run tests :)

Reviewed By: javache

Differential Revision: D66293212

fbshipit-source-id: dc232e1d3f7f8ae1578e894ce14bd21ccf3c8ade
2024-11-21 03:58:36 -08:00
Rubén Norte
92a476661c Add flag to force running tests in optimized mode (#47870)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47870

Changelog: [internal]

This flag allows us to run optimized mode by using the right buck modes for the Fantom CLI, using minified + dev in Metro and building bytecode using Buck as well.

It's disabled by default but in the future we can enable it based on the configuration in the test file (e.g.: if it's a benchmark) or we can run tests in both modes by default to catch problems caused by the differences between environments.

Reviewed By: rshest

Differential Revision: D66292709

fbshipit-source-id: d25294b739ff6a67507990241784b838d5b30dcd
2024-11-21 03:58:36 -08:00
Rubén Norte
b2f624d054 Add flag to print Fantom logs in Jest output (#47758)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47758

Changelog: [internal]

This helps with debugging when adding logs in native code. By default they're logged to stderr and not shown in the Jest output, but we can opt into getting them with this new flag.

Reviewed By: sammy-SC

Differential Revision: D66232572

fbshipit-source-id: d507fa4438ae46988fafc92123d0954ab3d27631
2024-11-20 10:00:48 -08:00
Rubén Norte
737045217b Implement expect().toEqual() (#47697)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47697

Changelog: [internal]

Implements `expect(received).toEqual(expected)` in Fantom tests.

Reviewed By: sammy-SC

Differential Revision: D66108539

fbshipit-source-id: 4e1d2405064900ec9859220fb6a28ec25a5176f3
2024-11-20 04:27:10 -08:00
Samuel Susla
6f1cf004fa add expect().toBeNull() (#47716)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47716

changelog: [internal]

Add toBeNull check to Fantom.

Jest docs: https://jestjs.io/docs/expect#tobenull

Reviewed By: javache

Differential Revision: D66167811

fbshipit-source-id: 33b6cf362bcf1636f41b78dc6c84905b80be994e
2024-11-19 10:52:08 -08:00
Rubén Norte
05874c831b Implement toThrow(message) with a specific error message string (#47700)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47700

Changelog: [internal]

Add support for the string parameter for `toThrow` to assert for specific error messages.

Reviewed By: sammy-SC

Differential Revision: D66118001

fbshipit-source-id: 8c04cd20d4ad17163ec0c7bf943c429507a97985
2024-11-19 07:56:49 -08:00
Rubén Norte
47882f0000 Implement jest.fn(), expect().toHaveBeenCalled() and expect().toHaveBeenCalledTimes() (#47699)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47699

Changelog: [internal]

Implements a `jest.fn()` and a subset of methods in `expect` using them (`.toHaveBeenCalled()` and `.toHaveBeenCalledTimes()`).

Reviewed By: sammy-SC

Differential Revision: D66118002

fbshipit-source-id: 5422307d68967d7d8b4c4d5155a45926f8fc8cae
2024-11-19 07:56:49 -08:00
Samuel Susla
4cb82501a3 add test for Suspense and Suspense with startTransition (#47714)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47714

changelog: [internal]

Reviewed By: rshest

Differential Revision: D66093340

fbshipit-source-id: 1db205d42d0570ab9c77ba0363ffac0d2dd81071
2024-11-19 07:41:17 -08:00
Rubén Norte
4da6ed5caf Use Meta-specific renderers when running tests in Meta infra (#47705)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47705

Changelog: [internal]

Reviewed By: sammy-SC

Differential Revision: D66094272

fbshipit-source-id: 25c0bc2d9e68ed1f4ede9dc5f0470a530b5db7d0
2024-11-19 05:53:26 -08:00
Rubén Norte
7be98c99bd Filter out AppRegistry logs from output (#47658)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47658

Changelog: [internal]

AppRegistry logs are showing up again in Fantom because we changed the order and now they're not necessarily showing up last.

This fixes that by filtering them out in any position.

Reviewed By: sammy-SC

Differential Revision: D66094274

fbshipit-source-id: bd37394252ee6309f7093567f9a2b73b641938ce
2024-11-18 04:38:43 -08:00
Samuel Susla
89a7238acd introduce ability to flush messege queue from tests (#47646)
Some checks are pending
Label closed PR as merged and leave a comment / comment-and-label (push) Waiting to run
Publish Bumped Packages / publish_bumped_packages (push) Waiting to run
Update node modules cache / update_node_modules_cache (push) Waiting to run
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47646

changelog: [internal]

In order to control scheduling of tests, test setup must be separated from test running. This is because of how internal scheduling of React Native is restricted until bundle is loaded via BufferedRuntimeExecutor. This is the reason for executing tests by calling global function `$$RunTests$$`. This is not a pretty solution but it is hidden within testing infrastructure and users of our test infra are not exposed to this.

There is a new method exposed to JavaScript: flushMessageQueue. This will flush everything that is inside of message queue. This is the queue where tasks are queued whenever RuntimeScheduler enqueues something by calling `runtimeExecutor_`.

Reviewed By: christophpurrer

Differential Revision: D65951894

fbshipit-source-id: 2e8e0c10fbeb998f4a51ee6d01ef229eb5f70448
2024-11-17 03:30:31 -08:00
Rubén Norte
058624fc1d Add support for focused and skipped tests in React Native integration tests (#47559)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47559

Changelog: [internal]

Adds support for focused and skipped tests and describe blocks:
* `fdescribe` / `describe.only`
* `xdescribe` / `describe.skip`
* `fit` / `it.only` / `test.only`
* `xit` / `it.skip` / `xtest` / `test.skip`

Reviewed By: rshest

Differential Revision: D65769325

fbshipit-source-id: ea26ae533400390b2efc4f2369340e5dc73c5d50
2024-11-15 03:00:17 -08:00
Rubén Norte
d417788b24 Hook up RN integration tests in Jest pipeline at Meta (#47613)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47613

Changelog: [internal]

Reviewed By: sammy-SC

Differential Revision: D65661703

fbshipit-source-id: 269444f8f7124082f06ffcf89cec40992a107d67
2024-11-15 03:00:17 -08:00
Rubén Norte
07b34f4ca3 Add Flow typing for test runner for RN integration tests (#47612)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47612

Changelog: [internal]

Just using babel-register so we can use Flow types in the code for the RN integration tests runner.

Reviewed By: sammy-SC

Differential Revision: D65948801

fbshipit-source-id: 6c54b0463fe4b71c818ff1c4faa973cc8b13b5d2
2024-11-15 03:00:17 -08:00
Rubén Norte
48b361688f Fix some broken expectations in RN integration tests (#47615)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47615

Changelog: [internal]

Fixes `.not` not being applied in some cases, and no logging the "not" label in case of error, and `.toBe` being flipped.

Reviewed By: javache

Differential Revision: D65952221

fbshipit-source-id: 030c0597b661d34e6324d69e5676375150a74f2e
2024-11-15 03:00:17 -08:00
Rubén Norte
849c139a4c Initial implementation of Jest test runner for RN integration tests (#47558)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47558

Changelog: [internal]

Reviewed By: sammy-SC

Differential Revision: D65661701

fbshipit-source-id: 0f0227debc769d0cebebc1989cbcfbbdd44dfc34
2024-11-14 06:20:47 -08:00
Tim Yung
c9ea05552f RN: Fix lint/sort-imports Errors (#47109)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47109

Fixes the `lint/sort-imports` errors that are now surfaced after fixing the lint configuration.

For a couple files, I added lint suppressions instead because the unsorted import ordering is important due to interleaved calls with side effects.

Changelog:
[Internal]

Reviewed By: GijsWeterings

Differential Revision: D64569485

fbshipit-source-id: 26415d792e2b9efe08c05d1436f723faae549882
2024-10-18 04:07:02 -07:00
Vitali Zaidman
8bbd3a8fb4 do not require @fb-tools/babel-register in open source (#46863)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46863

open source should not require `fb-tools/babel-register`

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D63976514

fbshipit-source-id: 83302adfc8059d294ca568f9edf1aa24d0244933
2024-10-07 09:36:47 -07:00
Alex Hunt
7c2a7de162 Bump Metro to 0.81.0-alpha.2 (#46703)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46703

Updates us in line with the release branch and unblocks https://github.com/facebook/react-native/pull/46627.

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D63544047

fbshipit-source-id: 4c093e6c2fc389888f12063df013db7023761859
2024-10-01 11:27:41 -07:00
Alex Hunt
33b78ee080 Substitute babel-preset-fbjs for metro-transform-plugins (#46689)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46689

Resubmission of D61014834 / https://github.com/facebook/react-native/pull/45959 (previously reverted).

> Addresses TODO comment. I noticed this lone reference to babel-preset-fbjs (last published 3y ago) while attempting to upgrade our Babel Flow syntax plugin.

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D63532211

fbshipit-source-id: e94b55b7b61194b50131b36a2fe817e149152953
2024-09-27 10:36:42 -07:00
Rexogamer
de2f9c0f77 fix: clean up various ESLint issues (#46379)
Summary:
this PR fixes a few small ESLint issues that were showing up under PR diffs.

## Changelog:

[INTERNAL] [FIXED] - Fix various ESLint issues

Pull Request resolved: https://github.com/facebook/react-native/pull/46379

Test Plan: ran JS tests + linter; all passing

Reviewed By: cipolleschi

Differential Revision: D62385788

Pulled By: NickGerleman

fbshipit-source-id: b33d7ade4696bbaed2ac1a3fc2e0b3dff9bb04b7
2024-09-17 13:07:20 -07:00
Gijs Weterings
f2aa3fe0ec Revert D61014834: Substitute babel-preset-fbjs for metro-transform-plugins
Differential Revision:
D61014834

Original commit changeset: 26bd1cacf890

Original Phabricator Diff: D61014834

fbshipit-source-id: 6879dc6e1dae7fdb59cfc3bd63ac090cffca26b0
2024-08-09 09:39:26 -07:00
Alex Hunt
82795715ae Substitute babel-preset-fbjs for metro-transform-plugins (#45959)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45959

Addresses TODO comment. I noticed this lone reference to `babel-preset-fbjs` (last published 3y ago) while attempting to upgrade our Babel Flow syntax plugin.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D61014834

fbshipit-source-id: 26bd1cacf8907550a5c318d4daf70359fb4f5700
2024-08-09 06:28:29 -07:00
Rob Hogan
2055ca0583 Set BUILD_EXCLUDE_BABEL_REGISTER: true under Jest tests (#42690)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42690

Issues triggered by `InspectorProxy*` tests under `packages/dev-middleware` (T169943794) can be root-caused to `dev-middleware` performing Babel registration within a test run, after Jest has hooked its own transformer.

Babel registration is only required when running this code (`dev-middleware`, etc) directly from source - we already have the `BUILD_EXCLUDE_BABEL_REGISTER` mechanism to strip it out from production builds, but we currently don't prevent registration under tests, where Jest's transformer should be allowed to do its work.

This adds the same `babel-plugin-transform-define` mechanism that we use for production builds to the Jest transformer.

Changelog:
[Internal] Prevent inadvertent Babel registration during running of repo tests

Reviewed By: huntie

Differential Revision: D53125777

fbshipit-source-id: 1f0a20315c96edaf79054e29a80c7a9561e5b352
2024-01-27 06:49:15 -08:00
Moti Zilberman
d6e0bc714a Enable lint/sort-imports everywhere (#41334)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41334

TSIA.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D51025812

fbshipit-source-id: e10d437be775a6b80946483aa96460f34927f870
2023-11-06 12:59:38 -08:00
Rob Hogan
5c513cb2f8 Register Babel in Jest setup to load transformer (#39251)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39251

As `react-native/babel-preset` is extended to include parts of codegen (written in Flow) via `react-native/babel-plugin-codegen`, we need to register Babel (with a Node JS config) in order to load the `react-native/babel-transformer` that Jest needs to transform RN code when running from source.

(This is *only* relevant to running from source, ie internally at Meta or when developing on a clone of the OSS repo)

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D48871440

fbshipit-source-id: 2f206b2380d67007e37782f211a6e831b35291f8
2023-09-01 04:43:41 -07:00
Moti Zilberman
408dd81fb6 Remove unused inlineRequires params from BabelTransformer API (#38771)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38771

Changelog: [Internal]

Metro has been passing `inlineRequires: false` to Babel transformers for the last 5 years (D9636747), as the inline requires transform had been hoisted into the transform worker. Here we clean up the unused code paths in React Native's implementations of the Metro Babel transformer API, and the unused properties in the API itself.

Reviewed By: GijsWeterings

Differential Revision: D48034441

fbshipit-source-id: d24a793962942a3c87461ffbade847ea749dac95
2023-08-07 09:17:43 -07:00
Dmitry Rykun
d380bb8473 Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo (#38228)
Summary:
X-link: https://github.com/facebook/metro/pull/1024

Pull Request resolved: https://github.com/facebook/react-native/pull/38228

Changelog: [General][Changed] - Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo.

Metro Changelog:  **[Breaking]** - Remove `metro-react-native-babel-transformer` and `metro-react-native-babel-preset`, to be published as `react-native/metro-babel-transformer` and `react-native/babel-preset` instead.

This diff does the following:
- Move `metro/packages/metro-react-native-babel-preset` to `react-native/packages/react-native-babel-preset`.
- Rename `metro-react-native-babel-preset` package to `react-native/babel-preset`.
- Move `metro/packages/metro-react-native-babel-transformer` to `react-native/packages/react-native-babel-transformer`.
- Rename `metro-react-native-babel-transformer` package to `react-native/metro-babel-transformer`.
- Upadate dependencies.

Reviewed By: robhogan

Differential Revision: D46977466

fbshipit-source-id: 32478f63a0442b61a1804f12ef814c8b29d7f8bb
2023-07-27 11:48:16 -07:00
Tim Yung
a7805bb20e RN: Upgrade to hermes-parser@0.14.0 (#38554)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38554

@public
Upgrades React Native, Relay, and Metro to use `hermes-parser@0.14.0`.

This also changes the repository's Jest configuration to now use `hermes-parser`.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D47522140

fbshipit-source-id: 207ccd0c4e4489d486731d0c847d8089abc1cc72
2023-07-24 11:30:39 -07:00
Rob Hogan
971bb81d13 Monorepo Jest - remove now unnecessary Babel registration (#38146)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38146

Now that `metro-react-native-babel-transformer` may be loaded from source without transformation, we can remove this workaround / potential footgun.

Jest uses Babel imperatively and doesn't rely on registration (require hooks), so registering within the preprocessor potentially conflicts and has caused problems before. This just tidies up some complexity we don't need.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D47162728

fbshipit-source-id: 06215f9bb7b8e71bcca0429d0bae9f20a22f45a8
2023-07-03 06:58:20 -07:00
Pieter Vanderwerff
dc2037c0f1 Switch xplat prettier config to hermes plugin (#37915)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37915

Enable the `prettier-plugin-hermes-parser` in xplat. This plugin enables the use of `hermes-parser` which is significantly faster than the current flow parser prettier bundles (improves formatting time by ~50%) and also brings support for the latest Prettier 3.0.0 printing logic for JS. This upgrade is required in order to enable upcoming Flow features that add new syntax.

Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D46748891

fbshipit-source-id: 3775ef9afa7c04e565fa4fcf8ca5b410f49d35a1
2023-06-15 08:23:06 -07:00
Rob Hogan
3c9d915330 Internal Jest setup - improve workaround for Babel registration (#36838)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36838

Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D44715939

fbshipit-source-id: fe3cbd934a39666e5590962941b1927b0f8e2610
2023-04-11 10:08:53 -07:00
Alex Hunt
c5a47abaf8 Bump RN CLI, add @react-native/metro-config to template (#36623)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36623

Changelog:
[General][Changed] - The default `metro.config.js` in apps now extends `react-native/metro-config`, and should be updated in existing apps.

~~`react-native/rn-get-polyfills.js` is removed and should be updated to `react-native/js-polyfills` in existing apps (this is part of the new default config).~~

#publish-packages-to-npm

## Context

### React Native Metro config → React Native repo (https://github.com/facebook/react-native/pull/36502)

We (the React Native team) are aiming to relocate the default Metro config for React Native out of `react-native-community/cli-plugin-metro` and **into the React Native repo + app template** as a new `react-native/metro-config` package.

This is the first (and minimum viable) phase we can ship to separate the release process of Metro from RN CLI in order to reduce coupling and iterate faster for our users.

**See full motivation, design, and test plan (which previewed the CLI bump) here: https://github.com/facebook/react-native/pull/36502**

## Changes

NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after https://github.com/react-native-community/cli/pull/1875 is merged.

- Upgrade `react-native-community/cli` to `11.0.0`, upgrade all `metro` packages to `0.76.0` (version distributed in this CLI release).
- Update the `metro.config.js` file in `packages/react-native/template/`.
    - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0.
- Update the `metro.config.js` files for `packages/react-native/` and `packages/rn-tester/` (these are integration test locations).
    - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0.

Changes to `react-native/metro-config` — `0.72.1` (prepared but not depended on yet):

- Export `mergeConfig` util (removing direct `metro-config` dependency in consuming projects).
- Explicitly depend on `metro-react-native-babel-transformer` and `metro-runtime` (transitively included today).

Reviewed By: cortinico, blakef

Differential Revision: D44099691

fbshipit-source-id: 405635dd69fd50a1e9548279eaeda3c932b5b167
2023-03-30 07:30:54 -07:00
Rob Hogan
a0fa3c736e Move Jest preprocessor up to workspace root, remove public metro-react-native-babel-transformer dep (#36523)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36523

`jest/private/preprocessor.js` is only used to run tests on the workspace itself, it's not part of our exported Jest preset and is specifically excluded from publication in the `react-native` package.

Now that we have the monorepo setup, this belongs at the workspace root.

 - `metro-react-native-babel-transformer` moved from RN `dependencies` to root `devDependencies` because it's only used by the preprocessor
 - `jest/create-cache-key-function` added to `devDependencies` - it's also used by the `assetTransformer` in the public preset.

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D44197879

fbshipit-source-id: 0bbd9e2f500f53fa4f16562f05374dc601b67df6
2023-03-20 05:44:34 -07:00
Ruslan Lesiutin
714b502b0c | RN Monorepo | Migrate to package (#36434)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36434

Changelog: [Internal]

This is a squashed stack of 18 commits, starting from D43202126

allow-large-files

Reviewed By: cortinico

Differential Revision: D43977381

fbshipit-source-id: 0da552ddb85f2f61a0be0ef071915b35f3f8555c
2023-03-17 05:03:25 -07:00
Alex Hunt
681d7f8113 Hotfix for Jest preset changes in 0a3c555 (#36495)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36495

It looks like Jest is not running `babel/transform-modules-commonjs` on all files, and therefore when including `"import"` as a Package Exports condition in Jest, this misbehaved (0a3c55562b).

This is a hotfix to restore CI stability.

Changelog:
[Fix][Internal] Hotfix adjusting Jest changes added in 0a3c55562b

Reviewed By: cipolleschi, hoxyq

Differential Revision: D44130442

fbshipit-source-id: 6407519d0d5459ef422afe21be26a2e3141bedf3
2023-03-16 04:57:16 -07:00
Alex Hunt
0a3c55562b Update custom "exports" conditions in Jest environment
Summary:
Updates the default set of `"exports"` condition names in our `ReactNativeEnv` for Jest, so that it aligns with the defaults in React Native CLI (https://github.com/react-native-community/cli/pull/1862).

Also includes a subtle update to how this is accomplished. Instead of overriding `exportConditions()`, we assign to the underlying class property — this allows users (once https://github.com/facebook/jest/pull/13989 is merged) to override `customExportConditions` via [`testEnvironmentOptions`](https://jestjs.io/docs/configuration#testenvironmentoptions-object).

```js
  preset: 'react-native',
  testEnvironmentOptions: {
    customExportConditions: ['test', 'react-native'],
  },
```

Changelog: [Internal]

Reviewed By: jacdebug

Differential Revision: D43879056

fbshipit-source-id: 86fffe2b5fdf9d8492d25b8b12a78be75b5fa3be
2023-03-15 17:18:08 -07:00
Nick Gerleman
cbc279c877 Fix Jest failure on console.error()
Summary:
The version using `jest.spyOn()` stopped working at some point. Couldn't find any relevant setup changes, but this form seems to work.

Changelog:
[Internal]

Reviewed By: christophpurrer

Differential Revision: D43669469

fbshipit-source-id: 89d207117e9a56ae3374aed47a8a75fdf2e644fd
2023-03-01 06:34:57 -08:00
Luna Wei
d504fb4145 Revert ESM imports
Summary:
Changelog: [Internal] - Remove all imports back to CJS for changelog in 0.72

We are reverting these imports as it may regress perf as we don't have a recommended inlining solution for ES modules at the current time.

Reviewed By: NickGerleman

Differential Revision: D43630911

fbshipit-source-id: ff3bb80009f327c4d51dad21f2cd287ce46d5964
2023-02-28 10:23:36 -08:00
Krzysztof Magiera
b44fe4deee Provide timestamp as argument to rAF callbacks when running Jest tests (#35919)
Summary:
This change aligns requestAnimationFrame implementation used in Jest environment with web standard, and with the implementation that runs in the application environment.

As per specification https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#parameters – requestAnimationFrame callback gets a single parameter, which represents the current frame timestamp. The current polyfill maps requestAnimationFrame directly to setTimeout which makes the callback execute without any parameters.

## Changelog

[General] [Fixed] - Jest mocked requestAnimationFrame callbacks now receive a timestamp parameter

Pull Request resolved: https://github.com/facebook/react-native/pull/35919

Test Plan:
1. execute jest test suite to make sure nothing breaks
2. add the below code to one of the tests:
```
jest.useFakeTimers();
requestAnimationFrame((timestamp) => console.log("rAF", timestamp));
jest.runOnlyPendingTimers();
jest.useRealTimers();
```
this code will print `undefined` before and numer `0` representing the mocked frame time after this change.

Reviewed By: jacdebug

Differential Revision: D42676544

Pulled By: robhogan

fbshipit-source-id: 363dc506ccc4bd034408fbb35ad3151875a8d309
2023-01-23 09:53:01 -08:00
Luna Wei
9c57a7f209 ESM ActivityIndicator
Summary: Changelog: [General][Changed] ActivityIndicator and remove .flow

Reviewed By: yungsters

Differential Revision: D42203449

fbshipit-source-id: 52ab1111166d23b7304e8406f299d23f9fd6f399
2023-01-03 18:09:06 -08:00
Luna Wei
0aece02cb0 ESM requireNativeComponent
Summary: Changelog: [General][Changed] - ESM requireNativeComponent

Reviewed By: yungsters

Differential Revision: D42200329

fbshipit-source-id: f1120f06362dc25e48551b3f2421bbda7b68c571
2023-01-03 18:09:06 -08:00
Luna Wei
f52aa9bf26 Support ES modules in mockComponent
Summary: Changelog: [Internal] Support ES modules in mockComponent

Reviewed By: christophpurrer

Differential Revision: D42270009

fbshipit-source-id: 31a857b3bb0486de3d4f05bf72973325f64dce34
2022-12-28 12:35:03 -08:00
Ruslan Lesiutin
71399d0891 refactor(react-native/polyfills): rename package to @react-native/js-polyfills and align version
Summary:
Changelog:
[General][Changed] - renamed react-native/polyfills -> react-native/js-polyfills and align with other packages versions (0.72.0) as a part of migration to monorepo

Reviewed By: motiz88

Differential Revision: D41553157

fbshipit-source-id: eef70c8e7639080acdeb6716d1a915760a85458a
2022-12-05 18:34:33 -08:00
Nick Gerleman
217696ee17 Fail tests on console.error() or console.warn()
Summary:
This makes it so that React Native unit tests will fail if code unexpectedly outputs a warning or error (which would show as a redbox error).

This logic split out from the normal `jest/setup.js` which is included by the jest-preset, to only effect our tests instead of existing RN Jest users.

Changelog:
[Internal][Changed] - Fail tests on `console.error()` or `console.warn()`

Reviewed By: huntie

Differential Revision: D41564032

fbshipit-source-id: 3cc7d3a8433fcb75f654669b9c350dea2da937a8
2022-12-01 06:59:04 -08:00
Moti Zilberman
6e9d3bf7b1 Revert D39268818: chore: rename polyfills to js-polyfills (umbrella 480)
Differential Revision:
D39268818 (ca1ae5c44f)

Original commit changeset: c87807460f27

Original Phabricator Diff: D39268818 (ca1ae5c44f)

fbshipit-source-id: 30fd72c56f530ed16b61094a53678daf0142f040
2022-11-26 10:28:56 -08:00
Thibault Malbranche
ca1ae5c44f chore: rename polyfills to js-polyfills (umbrella 480) (#34574)
Summary:
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[General] [Changed] - Rename polyfills to js-polyfills as part of https://github.com/react-native-community/discussions-and-proposals/pull/480

Pull Request resolved: https://github.com/facebook/react-native/pull/34574

Reviewed By: cipolleschi

Differential Revision: D39268818

Pulled By: hoxyq

fbshipit-source-id: c87807460f27fc83667d18c350a4a847459f056e
2022-11-25 15:57:13 -08:00
Simen Bekkhus
0376aa4856 fix(jest-env): pass exportConditions (#35203)
Summary:
Like discussed in https://github.com/react-native-community/discussions-and-proposals/issues/509, RN should override the default `node` and `node-addons` conditions.

You might consider supporting (or just setting) [`customExportConditions`](4670d3be0d/packages/jest-environment-node/src/index.ts (L187-L189)) instead, but the default of the node env should be overwritten 🙂

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[General] [Changed] - use `'react-native'` export conditions in Jest environment

Pull Request resolved: https://github.com/facebook/react-native/pull/35203

Test Plan: Green CI?

Reviewed By: lunaleaps

Differential Revision: D41081783

Pulled By: jacdebug

fbshipit-source-id: 844c70d92a58c5432ba5b9e5e99c8f50045ef8ac
2022-11-10 06:21:53 -08:00
Lorenzo Sciandra
cb2dcd327c feat(jest): move Jest config to use a custom react-native Jest env (#34971)
Summary:
This PR is the follow up to the conversation started here by SimenB: https://github.com/react-native-community/discussions-and-proposals/issues/509

Basically, we want to move RN to use its own custom environment so that we can tweak it going forward - this PR in fact only sets up the groundwork for that; robhogan mentioned that with this in place, Meta engineers can
> iterate on it (with jest-environment-node as a starting point) against our internal product tests

This is also connected to Rob's work to bring Jest 29 into the codebase https://github.com/facebook/react-native/pull/34724 and my "mirror" PR to bring template in main up to the same version (https://github.com/facebook/react-native/pull/34972)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[General] [Changed] - move Jest config to use a custom react-native Jest env

Pull Request resolved: https://github.com/facebook/react-native/pull/34971

Test Plan: Tested that `yarn test` in main works fine after the changes; CI and Meta's internal CI will also serve the purpose of verifying that it works (but there's no reason not to since it's still pretty much just relying on `node`).

Reviewed By: huntie

Differential Revision: D40379760

Pulled By: robhogan

fbshipit-source-id: 2c6d0bc86d337fda9befce0799bda2f56cc4466c
2022-10-17 12:40:25 -07:00
Adrian Hartanto
2aba3522ab fix: adjust clipboard mock (#34672)
Summary:
Currently, Clipboard's methods (setString, getString) can't be asserted when writing tests as the mock targeted `Libraries/BatchedBridge/NativeModules` instead of `Libraries/Components/Clipboard/Clipboard` that's used on react-native [entry point](https://github.com/facebook/react-native/blob/main/index.js#L270) so it won't be considered as `mock function`.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[General] [Changed] - Update `Clipboard` mock path

Pull Request resolved: https://github.com/facebook/react-native/pull/34672

Test Plan:
```js
// App-test.js

import { Clipboard } from 'react-native';
import React from 'react';

it('renders correctly', () => {
  Clipboard.setString('string');
  expect(Clipboard.setString).toBeCalled();
});
```

### before

<img width="473" alt="Screen Shot 2022-09-13 at 16 24 30" src="https://user-images.githubusercontent.com/5382429/189864957-6b926478-6781-4291-a1eb-4493779de1a2.png" />

### after

<img width="598" alt="Screen Shot 2022-09-13 at 16 26 34" src="https://user-images.githubusercontent.com/5382429/189865131-e7c39f97-1cc1-4eb9-b4c0-d9ddf7a05c9c.png" />

Reviewed By: yungsters

Differential Revision: D39575916

Pulled By: cortinico

fbshipit-source-id: 34a3f93986a18d349ac033bb13a10ed77689935c
2022-09-16 08:54:05 -07:00