question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest transform support / documentation

See original GitHub issue

Hi, thanks for the awesome library. Nice to see proper TypeScript support in React Native.

As Jest is the default test runner in React Native projects created by by the react-native cli tool, it would be nice to see support or documentation on how to use this library as the transformer for Jest as well.

Of course the alternative is to use https://github.com/lozinsky/typescript-babel-jest, but would somehow be nice to use the same transformation for tests and production.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
vovkasmcommented, Sep 18, 2017

I just try preprocess jest tests with this module and it seems to work well with small glue code. Although my test suite is small and I may not detect all edge cases, it would be good to have this “glue” in package itself and improve it together.

My config: jest/preprocessor.js (actually it is adaptation of RN jest preprocessor)

var tsTransformer = require('react-native-typescript-transformer')
var rnTransformer = require('react-native/jest/preprocessor')

var preprocessor = Object.assign({}, rnTransformer, {
  process (src, file) {
    return tsTransformer.transform({
      filename: file,
      localPath: file,
      options: {
        dev: true,
        inlineRequires: true,
        platform: '',
        projectRoot: '',
        retainLines: true,
      },
      src,
    }).code
  },
})

module.exports = preprocessor

package.json (jest config part)

  "jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.[jt]sx?$": "<rootDir>/jest/preprocessor.js"
    },
    "testMatch": [
      "**/*.spec.{js,jsx,ts,tsx}"
    ],
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ]
  },

What do you think?

2reactions
ds300commented, Feb 5, 2018

Happy to have your input @GeeWee !

I agree that it makes most sense to focus on ts-jest. It should work, and it has a lot of useful things that react-native-typescript-transformer lacks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code Transformation
A transformer is a module that provides a method for transforming source files. For example, if you wanted to be able to use...
Read more >
ts-jest/esm-support.md at main
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. - ts-jest/esm-support.md at main ...
Read more >
storybook/addon-docs
Storybook Docs transforms your Storybook stories into world-class component ... Just like Storybook, Docs supports every major view layer ...
Read more >
Configuring package.json · Jest
Jest's configuration can be defined in the package.json file of your project or through the ... transform [object<string, string>]; transformIgnorePatterns ...
Read more >
Testing with Jest
Learn how to set up and configure the jest-expo package to write unit tests and ... This can be done by including the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found