Coder Social home page Coder Social logo

Usage with ts-jest about ts-transformer-keys HOT 5 CLOSED

kimamula avatar kimamula commented on August 20, 2024
Usage with ts-jest

from ts-transformer-keys.

Comments (5)

DamianPereira avatar DamianPereira commented on August 20, 2024 1

I managed to do it, I had to create a file like this:

// ts-jest-keys-trasnformer.js
const keysTransformer = require('ts-transformer-keys/transformer').default;
const name = 'my-key-transformer';
const version = 1;
const factory = (cs) => (ctx) => keysTransformer(cs.tsCompiler.program)(ctx);
module.exports = { name, version, factory };

And add it in jest.config.js like this:

  globals: {
        'ts-jest': {
          // relative path to the ts-jest-keys-transformer.js file
          astTransformers: ['src/react/ts-jest-keys-transformer.js'],
        },
      },

I'll create a PR adding an example and documentation

from ts-transformer-keys.

EdNutting avatar EdNutting commented on August 20, 2024 1

This was brilliant - thank you! Never would've figured out how to get this working without your solution.

from ts-transformer-keys.

DamianPereira avatar DamianPereira commented on August 20, 2024

Glad I could help :)

from ts-transformer-keys.

PyDario avatar PyDario commented on August 20, 2024

Unfortunately, this didn't work for me. program is undefined in this test

 ● Test suite failed to run

    TypeError: Cannot read property 'program' of undefined

      2 | const name = 'my-key-transformer';
      3 | const version = 1;
    > 4 | const factory = cs => ctx => keysTransformer(cs.tsCompiler.program)(ctx);
        |                                                            ^
      5 | module.exports = { name, version, factory };
      6 |

      at ts-jest-keys-transformer.js:4:60
      at node_modules/typescript/lib/typescript.js:96726:37
      at node_modules/typescript/lib/typescript.js:96819:78
          at Array.map (<anonymous>)
      at Object.transformNodes (node_modules/typescript/lib/typescript.js:96819:52)
      at emitJsFileOrBundle (node_modules/typescript/lib/typescript.js:97443:32)
      at emitSourceFileOrBundle (node_modules/typescript/lib/typescript.js:97395:13)
      at forEachEmittedFile (node_modules/typescript/lib/typescript.js:97147:34)
      at Object.emitFiles (node_modules/typescript/lib/typescript.js:97376:9)
      at emitWorker (node_modules/typescript/lib/typescript.js:103688:33)

Edit:
I'm using the following packages:
jest: 27.1.0
ts-transformer-keys: 0.4.3
typescript: 4.0.2

from ts-transformer-keys.

HCanber avatar HCanber commented on August 20, 2024

ts-jest 27.x.x has breaking changes. Update:

- const factory = cs => ctx => keysTransformer(cs.tsCompiler.program)(ctx);
+ const factory = cs => ctx => keysTransformer(cs.program)(ctx);

from ts-transformer-keys.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.