ts-jest icon indicating copy to clipboard operation
ts-jest copied to clipboard

[Bug]: Getting warning even after adding to ignoreCodes

Open anandhsonu1994 opened this issue 2 years ago • 3 comments

Version

29.0.1

Steps to reproduce

  1. Add TS151001 in ignoreCodes in ts-jest config transform: { '^.+\.(t|j)sx?$': [ 'ts-jest', { diagnostics: { ignoreCodes: "TS151001" }, } ] }
  2. Run "jest --config jest.config.ts" command

Expected behavior

The warning should be ignored

Actual behavior

Still getting the warnings

Debug log

ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information. ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting esModuleInterop to true in your TypeScript configuration file (usually tsconfig.json). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.0.3 => 29.0.3

anandhsonu1994 avatar Sep 19 '22 07:09 anandhsonu1994

@anandhsonu1994 if you try this in ts-jest 28 does it work? I'm seeing an error in my world where using ts-jest 28, my the transformer is called but in ts-jest 29 it doesn't. I just haven't had time to write the reproducible test case. NOTE: you probably need to switch things to use the global option in your jest config file with 28

heath-freenome avatar Sep 20 '22 00:09 heath-freenome

@heath-freenome With ts-jest 28.0.8 and

    "extensionsToTreatAsEsm": [
      ".ts"
    ],
    "globals": {
      "ts-jest": {
        "useESM": true,
        "diagnostics": {
          "ignoreCodes": [
            "TS151001"
          ]
        }
      }
    },
    "moduleNameMapper": {
      "^(\\.{1,2}/.*)\\.js$": "$1"
    },
    "preset": "ts-jest/presets/default-esm",

the warning is not printed.

With ts-jest 29.0.1 and same configuration with "globals",

ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
    <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.

and the tests never complete. It looks like the "globals" would not be deprecated but is getting completely ignored now.

I tried to replace "globals" with "transform":

    "transform": {
      "^.+\\.(ts|tsx|js|jsx)$": ["ts-jest", {
        "useESM": true,
        "diagnostics": {
          "ignoreCodes": [
            "TS151001"
          ]
        }
      }]
    },

(and various other file matching regexes) but always get the same result.

Also yarn ts-jest config:migrate package.json still prints out the "globals" as-is and doesn't migrate them to "transform".

okko avatar Sep 20 '22 09:09 okko

@okko So you ARE seeing the same issue I am. The transformers that work in ts-jest 28 do NOT work in ts-jest 29 no matter how you configure them (deprecated or not). Are you able to build a codesandbox.io reproducible test case? I know that makes it easier for @longlho to fix these kinds of issues.

heath-freenome avatar Sep 20 '22 15:09 heath-freenome

Can you guys please provide a repo? or use this examples https://github.com/kulshekhar/ts-jest/tree/main/examples to make a reproduce scenario. Thanks.

ahnpnl avatar Sep 25 '22 10:09 ahnpnl

I will try to get one for my similar (but different) issue sometime within a week

heath-freenome avatar Sep 28 '22 23:09 heath-freenome

Hmmm, my issue went away with v29.0.3 so YAY! Ok, it went away via the globals syntax but using the other syntax still fails for me... AHHHH! leaving ts-jest as a preset fails, but removing it along with adding this as my transform works:

Before:

{
  ... // other presets
  "preset": "ts-jest",
  "globals": {
    "ts-jest": {
      "astTransformers": {
        "before": [
          {
            "path": "@formatjs/ts-transformer/ts-jest-integration",
            "options": {
              "overrideIdFn": "[sha512:contenthash:base64:6]",
              "ast": true
            }
          }
        ]
      }
    }
  }
}

After:

{
  ... // other presets
  "transform": {
    "\\.tsx?$": [
      "ts-jest", {
        "astTransformers": {
          "before": [
            {
              "path": "@formatjs/ts-transformer/ts-jest-integration",
              "options": {
                "overrideIdFn": "[sha512:contenthash:base64:6]",
                "ast": true
              }
            }
          ]
        }
      }
    ]
}

heath-freenome avatar Sep 30 '22 17:09 heath-freenome

@okko Maybe 29.0.3 fixes your issue too?

heath-freenome avatar Sep 30 '22 17:09 heath-freenome

@heath-freenome Indeed it does! Thank you for the ping and the reference!

okko avatar Oct 06 '22 14:10 okko