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

Support for Jest 28 #3347

Merged
merged 5 commits into from
Jul 1, 2022
Merged

Support for Jest 28 #3347

merged 5 commits into from
Jul 1, 2022

Conversation

piaskowyk
Copy link
Member

@piaskowyk piaskowyk commented Jul 1, 2022

Description

Add support for Jest 28 with backward compatibility.

Based on: #3217

@piaskowyk piaskowyk self-assigned this Jul 1, 2022
matt-oakes and others added 3 commits July 1, 2022 12:47
## Description

Fixes for Jest 28 compatability (Issue #3215)

## Changes

- Change the import for expect to maintain compatability with Jest 28.
- Updated the documentation to ensure the enviornment is set up before running the script.

## Checklist

- [x] Included code example that can be used to test this change
- [x] Updated TS types
- [x] Added TS types tests
- [x] Added unit / integration tests
- [x] Updated documentation
- [x] Ensured that CI passes
@piaskowyk piaskowyk marked this pull request as ready for review July 1, 2022 11:28
@piaskowyk piaskowyk changed the title Update for Jest 28 Support for Jest 28 Jul 1, 2022
Copy link
Member

@graszka22 graszka22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

@piaskowyk piaskowyk merged commit 930b2d1 into main Jul 1, 2022
@piaskowyk piaskowyk deleted the @piaskowyk/jest-28-support branch July 1, 2022 11:38
piaskowyk added a commit that referenced this pull request Jul 1, 2022
## Description

Add support for Jest 28 with backward compatibility.

Based on: #3217
This was referenced Jul 4, 2022
@parasharrajat
Copy link

Please, any hint on when the new version will be released.

const expect = require('expect');
let expect;
try {
expect = require('expect');
Copy link

@parasharrajat parasharrajat Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will not throw on jest v28. As per the upgrade guide https://jestjs.io/docs/28.x/upgrading-to-jest28#expect, expect here will be set to undefined and no error. i.e. Catch will never fire.

@parasharrajat
Copy link

Still facing this #3215 after upgrading to 2.10.0.

@neiker
Copy link

neiker commented Sep 6, 2022

@parasharrajat this changes are only included on v3

@parasharrajat
Copy link

@neiker But I can see the code changes in tag V2.10.0

const { expect: expectModule } = require('@jest/globals');

@neiker
Copy link

neiker commented Sep 8, 2022

That's strange, it's not in the changelog for that version
https://github.com/software-mansion/react-native-reanimated/releases

piaskowyk pushed a commit that referenced this pull request Nov 3, 2022
## Description
Reanimated is not fully compatible with Jest 28+ even after the PR #3347. Using it with Jest 28+ leads to this error:

<img width="796" alt="Ekran Resmi 2022-09-10 15 00 33" src="https://user-images.githubusercontent.com/22980987/189482337-cc2655f6-9463-4a05-9998-5fc3592f5cc0.png">

The reason is, the "expect" module's export approach has changed starting from Jest 28. It used to export the `expect` function directly, as can be seen [here](https://github.com/facebook/jest/blob/v27.5.1/packages/expect/src/index.ts#L441). 

This means, requiring the "expect" module like this

```ts
const expect = require('expect')
```

was providing direct access to the `expect` function alongside with its attached methods, like `extend`.

This has [changed with Jest 28](https://github.com/facebook/jest/blob/v28.0.0/packages/expect/src/index.ts#L449). `export default expect` is the new export statement, which means requiring the "expect" package returns the module object, instead of the function.

#3347 PR attempts to fix this error by assuming "expect" package should throw an error with Jest 28 and it can catch that and require the "expect" from the `@jest/globals` package for Jest 28+ project but it's not the case in reality. "expect" package is still shipped with Jest 28, so, requiring it doesn't throw an error as expected in the PR.

By knowing the export difference, I checked if the value of the module is object or not after requiring it. If it's an object, it means user is on Jest 28+ codebase. The rest is the same with the previous PR. I require the "expect" function from `@jest/globals` and use it.

Tested on Jest 29 and Jest 27.5.1

Fixes #3553 and #3215.
piaskowyk pushed a commit that referenced this pull request Nov 3, 2022
## Description
Reanimated is not fully compatible with Jest 28+ even after the PR #3347. Using it with Jest 28+ leads to this error:

<img width="796" alt="Ekran Resmi 2022-09-10 15 00 33" src="https://user-images.githubusercontent.com/22980987/189482337-cc2655f6-9463-4a05-9998-5fc3592f5cc0.png">

The reason is, the "expect" module's export approach has changed starting from Jest 28. It used to export the `expect` function directly, as can be seen [here](https://github.com/facebook/jest/blob/v27.5.1/packages/expect/src/index.ts#L441). 

This means, requiring the "expect" module like this

```ts
const expect = require('expect')
```

was providing direct access to the `expect` function alongside with its attached methods, like `extend`.

This has [changed with Jest 28](https://github.com/facebook/jest/blob/v28.0.0/packages/expect/src/index.ts#L449). `export default expect` is the new export statement, which means requiring the "expect" package returns the module object, instead of the function.

#3347 PR attempts to fix this error by assuming "expect" package should throw an error with Jest 28 and it can catch that and require the "expect" from the `@jest/globals` package for Jest 28+ project but it's not the case in reality. "expect" package is still shipped with Jest 28, so, requiring it doesn't throw an error as expected in the PR.

By knowing the export difference, I checked if the value of the module is object or not after requiring it. If it's an object, it means user is on Jest 28+ codebase. The rest is the same with the previous PR. I require the "expect" function from `@jest/globals` and use it.

Tested on Jest 29 and Jest 27.5.1

Fixes #3553 and #3215.
geriux pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jan 25, 2023
…n#3559)

Reanimated is not fully compatible with Jest 28+ even after the PR software-mansion#3347. Using it with Jest 28+ leads to this error:

<img width="796" alt="Ekran Resmi 2022-09-10 15 00 33" src="https://user-images.githubusercontent.com/22980987/189482337-cc2655f6-9463-4a05-9998-5fc3592f5cc0.png">

The reason is, the "expect" module's export approach has changed starting from Jest 28. It used to export the `expect` function directly, as can be seen [here](https://github.com/facebook/jest/blob/v27.5.1/packages/expect/src/index.ts#L441).

This means, requiring the "expect" module like this

```ts
const expect = require('expect')
```

was providing direct access to the `expect` function alongside with its attached methods, like `extend`.

This has [changed with Jest 28](https://github.com/facebook/jest/blob/v28.0.0/packages/expect/src/index.ts#L449). `export default expect` is the new export statement, which means requiring the "expect" package returns the module object, instead of the function.

software-mansion#3347 PR attempts to fix this error by assuming "expect" package should throw an error with Jest 28 and it can catch that and require the "expect" from the `@jest/globals` package for Jest 28+ project but it's not the case in reality. "expect" package is still shipped with Jest 28, so, requiring it doesn't throw an error as expected in the PR.

By knowing the export difference, I checked if the value of the module is object or not after requiring it. If it's an object, it means user is on Jest 28+ codebase. The rest is the same with the previous PR. I require the "expect" function from `@jest/globals` and use it.

Tested on Jest 29 and Jest 27.5.1

Fixes software-mansion#3553 and software-mansion#3215.
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
## Description

Add support for Jest 28 with backward compatibility.

Based on: software-mansion#3217
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…n#3559)

## Description
Reanimated is not fully compatible with Jest 28+ even after the PR software-mansion#3347. Using it with Jest 28+ leads to this error:

<img width="796" alt="Ekran Resmi 2022-09-10 15 00 33" src="https://user-images.githubusercontent.com/22980987/189482337-cc2655f6-9463-4a05-9998-5fc3592f5cc0.png">

The reason is, the "expect" module's export approach has changed starting from Jest 28. It used to export the `expect` function directly, as can be seen [here](https://github.com/facebook/jest/blob/v27.5.1/packages/expect/src/index.ts#L441). 

This means, requiring the "expect" module like this

```ts
const expect = require('expect')
```

was providing direct access to the `expect` function alongside with its attached methods, like `extend`.

This has [changed with Jest 28](https://github.com/facebook/jest/blob/v28.0.0/packages/expect/src/index.ts#L449). `export default expect` is the new export statement, which means requiring the "expect" package returns the module object, instead of the function.

software-mansion#3347 PR attempts to fix this error by assuming "expect" package should throw an error with Jest 28 and it can catch that and require the "expect" from the `@jest/globals` package for Jest 28+ project but it's not the case in reality. "expect" package is still shipped with Jest 28, so, requiring it doesn't throw an error as expected in the PR.

By knowing the export difference, I checked if the value of the module is object or not after requiring it. If it's an object, it means user is on Jest 28+ codebase. The rest is the same with the previous PR. I require the "expect" function from `@jest/globals` and use it.

Tested on Jest 29 and Jest 27.5.1

Fixes software-mansion#3553 and software-mansion#3215.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants