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

jest-expo failed testing createCacheKeyFunction #13886

Closed
joseocabarcas opened this issue Aug 2, 2021 · 5 comments
Closed

jest-expo failed testing createCacheKeyFunction #13886

joseocabarcas opened this issue Aug 2, 2021 · 5 comments

Comments

@joseocabarcas
Copy link

Summary

Hi, I'm having trouble updating to SDK 42 to run unit tests.
I am having this error with jest-expo

Cannot find module 'fbjs-scripts/jest/createCacheKeyFunction'
    Require stack:
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\jest-expo\src\preset\assetFileTransformer.js
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\@jest\transform\build\ScriptTransformer.js
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\@jest\transform\build\index.js
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\jest-runtime\build\index.js
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\jest-runner\build\testWorker.js
    - C:\Users\jocab\WorkSpaceElenas\elenas\app\node_modules\jest-worker\build\workers\processChild.js

    Require stack:
      node_modules/jest-expo/src/preset/assetFileTransformer.js
      node_modules/@jest/transform/build/ScriptTransformer.js
      node_modules/@jest/transform/build/index.js
      node_modules/jest-runtime/build/index.js
      node_modules/jest-runner/build/testWorker.js
      node_modules/jest-worker/build/workers/processChild.js

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

42

Environment

Expo CLI 4.9.1 environment info:
System:
OS: Windows 10 10.0.19043
Binaries:
Node: 14.17.3 - C:\Users\jocab\AppData\Local\Temp\yarn--1627936221009-0.16358276054367216\node.CMD
Yarn: 1.22.4 - C:\Users\jocab\AppData\Local\Temp\yarn--1627936221009-0.16358276054367216\yarn.CMD
npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
Watchman: 20200424.164118.0 - C:\Users\jocab\watchman\windows\bin\watchman.EXE
SDKs:
Android SDK:
API Levels: 23, 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
System Images: android-23 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085
npmPackages:
expo: ^42.0.0 => 42.0.0
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
react-native: 0.64.2 => 0.64.2
react-native-web: ~0.13.12 => 0.13.18
Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

N/A

@joseocabarcas joseocabarcas added the needs validation Issue needs to be validated label Aug 2, 2021
@joseocabarcas
Copy link
Author

This is jest.config.js

const expoPreset = require("jest-expo/jest-preset.js");

module.exports = {
  preset: "jest-expo",
  transformIgnorePatterns: [
    "node_modules/(?!(jest-)?react-native|@react-native|unimodules-permissions-interface|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|native-base|@sentry/react-native|@segment/analytics-react-native/.*|@ui-kitten)|@wootric/react-native-wootric/.*|@ui-kitten",
    // "node_modules/@ui-kitten",
  ],
  // transform: expoPreset.transform,
  testPathIgnorePatterns: ["<rootDir>/node_modules"],
  // setupFiles: [...expoPreset.setupFiles, "<rootDir>/setUpFileJest.js"],
  setupFiles: ["<rootDir>/setUpFileJest.js"],
  setupFilesAfterEnv: ["@testing-library/jest-native/extend-expect"],
  coverageReporters: ["text", "cobertura", "lcov"],
  moduleNameMapper: {
    "\\.svg": "<rootDir>/__mocks__/svgMock.js"
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  verbose: true,
  collectCoverageFrom: [
    "**/*.{ts,tsx}",
    "!**/coverage/**",
    "!**/node_modules/**",
    "!**/babel.config.js",
    "!**/jest.setup.js",
  ]
};

@crcass
Copy link

crcass commented Aug 3, 2021

I was able to get around this issue by adding fbjs-scripts under devDependencies in my package.json

npm i fbjs-scripts --save-dev
or
yarn add fbjs-scripts --dev

I also needed to add @jest/create-cache-key-function under resolutions in my package.json per a reply to this issue

@byCedric
Copy link
Member

byCedric commented Aug 3, 2021

This issue happens if you are using a newer React Native version, e.g. 0.64.2. In this React Native version, fbjs-scripts is removed. We will fix this when we upgrade our internal React Native version to 0.64.x. For now, the best workaround would be to use @crcass's workaround.

@joseocabarcas
Copy link
Author

Yes, I downgraded to the version 0.63 and it is fixed. For now, I will use @crcass workaround.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Sep 8, 2021
`jest-expo` has a bug where it imports `fbjs-scripts` library but
doesn't declare it as a dependency. This hasn't caused any issues so
far because React Native has been pulling in `fbjs-scripts`, and
`jest-expo` uses it from there.

But RN v0.64 stops pulling in `fbjs-scripts`, so things fail [1].

So, until we get a version of `jest-expo` that declares
`fbjs-scripts` as a dependency, or (preferably) consumes the code
from its new home at @jest/create-cache-key-function [2] (and
hopefully declares *that* as a dependency), we should keep
`fbjs-scripts` as our own direct dependency. Since this is meant to
be a temporary state, and to keep down complexity, just pin to the
exact version that RN pulls in in RN v0.63, which is 1.2.0.

[1] expo/expo#13886 (comment)
[2] See facebook/react-native@fd9787ecc.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Sep 8, 2021
`jest-expo` has a bug where it imports `fbjs-scripts` library but
doesn't declare it as a dependency. This hasn't caused any issues so
far because React Native has been pulling in `fbjs-scripts`, and
`jest-expo` uses it from there.

But RN v0.64 stops pulling in `fbjs-scripts`, so things fail [1].

So, until we get a version of `jest-expo` that declares
`fbjs-scripts` as a dependency, or (preferably) consumes the code
from its new home at @jest/create-cache-key-function [2] (and
hopefully declares *that* as a dependency), we should keep
`fbjs-scripts` as our own direct dependency. Since this is meant to
be a temporary state, and to keep down complexity, just pin to the
exact version that RN pulls in in RN v0.63, which is 1.2.0.

[1] expo/expo#13886 (comment)
[2] See facebook/react-native@fd9787ecc.
@schematis
Copy link

Forgive me if I'm misunderstanding, but as of SDK 43 beta 4 this is not fixed and 43 includes RN 0.64.2. Will this be fixed in the final release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants