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

ts-jest support #1272

Closed
kopax-polyconseil opened this issue Jul 26, 2022 · 4 comments
Closed

ts-jest support #1272

kopax-polyconseil opened this issue Jul 26, 2022 · 4 comments

Comments

@kopax-polyconseil
Copy link

Is your feature request related to a problem? Please describe.

We use lingui since a while and despite it's cool to use, our app now gets bigger and the amount of unit tests too. For this reason, we wanted to switch to ts-jest instead of babel-jest to improve our tests perfs, but it is not possible as lingui does not support ts-jest.

With ts-jest, we got this error everywhere:

    TypeError: (0 , macro_1.t) is not a function

Describe proposed solution

Support for ts-jest

Describe alternatives you've considered

Removing lingui as we don't really need translation.

Additional context

{
    "@lingui/core": "^3.13.2",
    "@lingui/react": "^3.13.2",
    "@lingui/cli": "^3.13.2",
    "@lingui/macro": "^3.13.2",
}
@kopax-polyconseil
Copy link
Author

kopax-polyconseil commented Jul 27, 2022

I started to use a mock for jest, unfortunately, this is what I did and it is not ready yet:

export const t = (text: string | Array<string>) => {
  if (typeof text === text) {
    return text.trim()
  } else if (text instanceof Array) {
    return text.map((t) => t.trim()).join(' ')
  }
  return text
}

type Plural = {
  value: number
  one: string
  other: string
}

export const plural = (count: number | Plural, plural: Plural) => {
  if (isNaN(count as number)) {
    plural = count as Plural
    if (plural.value <= 1) {
      return plural.one.replace('#', `${plural.value}`)
    }
    return plural.other.replace('#', `${plural.value}`)
  }
  if (count <= 1) {
    return plural.one.replace('#', `${count}`)
  }
  return plural.other.replace('#', `${count}`)
}

If guys want to help get further :)

@stale
Copy link

stale bot commented Sep 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

1 similar comment
@stale
Copy link

stale bot commented Nov 26, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@timofei-iatsenko
Copy link
Collaborator

@andrii-bodnar @kopax-polyconseil supporting also typescript transformation in additional to SWC and babel plugin has no sense as it means complete rewrite the whole macro as typescrit transformation and supporting all 3 versions. Where typescript transformations has no advantages over SWC or babel.

@kopax-polyconseil if you want to speedup your test it's better to try SWC, as it's dozen times faster than typescript and babel. Lingui plugin for SWC is almost ready. #1224

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