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

Vanilla React Native project doesn't work with @swc/jest based on usage instructions #8198

Closed
jzaefferer opened this issue Oct 30, 2023 · 2 comments
Labels

Comments

@jzaefferer
Copy link

jzaefferer commented Oct 30, 2023

Describe the bug

When creating a vanilla React Native project, based on https://reactnative.dev/docs/environment-setup (run npx react-native@latest init AwesomeProjectSwc), then following the @swc/jest instructions for using swc with jest ( https://swc.rs/docs/usage/jest ), running yarn test will then fail with this unexpected error:

$ yarn test
yarn run v1.22.19
$ jest
 FAIL  __tests__/App.test.tsx
  ● Test suite failed to run


      × Expected ';', '}' or <eof>
        ╭─[~/AwesomeProjectSwc/node_modules/@react-native/js-polyfills/error-guard.js:11:1]
     11 │
     12 │ let _inGuard = 0;
     13 │
     14 │ type ErrorHandler = (error: mixed, isFatal: boolean) => void;
        · ──┬─ ────────────
        ·   ╰── This is the expression part of an expression statement
     15 │ type Fn<Args, Return> = (...Args) => Return;
     16 │
     17 │ /**
        ╰────


    Caused by:
        Syntax Error

      at Compiler.transformSync (node_modules/@swc/core/index.js:244:29)
      at transformSync (node_modules/@swc/core/index.js:351:21)
      at Object.process (node_modules/@swc/jest/index.js:73:45)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:545:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:674:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:726:19)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.074 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Input code

No response

Config

No response

Playground link (or link to the minimal reproduction)

https://github.com/jzaefferer/swc-jest-react-native-repro

SWC Info output

$ npx -y swc-info@latest

Operating System:
    Platform: darwin
    Arch: arm64
    Machine Type: arm64
    Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    CPU: (10 cores)
        Models: Apple M1 Max

Binaries:
    Node: 16.19.1
    npm: 8.19.3
    Yarn: 1.22.19
    pnpm: 8.10.0

Relevant Packages:
    @swc/core: 1.3.95
    @swc/helpers: N/A
    @swc/types: 0.1.5
    typescript: 4.8.4

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

Jest tests should run

Actual behavior

No response

Version

"@swc/core": "^1.3.95", "@swc/jest": "^0.2.29",

Additional context

swc-project/jest#40 (comment) looks somewhat related, but the suggested fix didn't work for me.

Looking for jest and this file name, which seems to be implemented in flow, I also found react-native-community/upgrade-support#152 - but adding the suggested transformIgnorePatterns didn't help either.

The repro repo uses the react-native Jest preset, which already includes transformIgnorePatterns: https://github.com/facebook/react-native/blob/0.72-stable/packages/react-native/jest-preset.js

https://github.com/swc-project/jest has more information than https://swc.rs/docs/usage/jest - might be worth linking to the GitHub readme. Though I didn't found a solution there either.

@kdy1
Copy link
Member

kdy1 commented Oct 30, 2023

swc-project/jest#85

It's not a bug of swc. Flow type should be stripped out before publishing a library.

@swc-bot
Copy link
Collaborator

swc-bot commented Nov 30, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants