electron-svelte-typescript icon indicating copy to clipboard operation
electron-svelte-typescript copied to clipboard

Warning message running `npm test`

Open jtlapp opened this issue 4 years ago • 4 comments

Using this template unmodified, I get this message running npm test:

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.

With this dummy test file:

import * as path from 'path'

test("dummy test", () => {
  expect(path.join("xyz", "pdq")).toEqual("xyz/pdq")
})

The message remains no matter in which tsconfig.json I put the following lines:

  "allowSyntheticDefaultImports": true,
  "esModuleInterop": true,

jtlapp avatar Oct 13 '21 16:10 jtlapp

I have not written any tests with this setup and I do not have a lot of time but I will accept a PR if you write one.

Cheers.

fuzzc0re avatar Jan 07 '22 09:01 fuzzc0re

In my case setting "esModuleInterop": true fixed the problem. Remember this esModuleInterop will also set allowSyntheticDefaultImports to true. So no need to set this one to true explicitly. Details below ⬇️

https://www.typescriptlang.org/tsconfig#esModuleInterop

chety avatar Mar 14 '23 15:03 chety

Having the same issue

Exy63 avatar Apr 20 '23 12:04 Exy63

In my case, setting "esModuleInterop": true did in fact suppress these warnings (ts-jest 29.1.2, jest 29.7.0) so I can't reproduce this exact bug as described.

But I don't want esModuleInterop true (which always emits extra bulky shim code), searched for how to disable these pesky warnings, and found this page. If anybody else is in a similar situation, you can suppress the warnings explicitly by adjusting your jest.config from this style of ts-jest invocation:

module.exports = {
  transform: {
    "^.+\\.(t|j)s$": "ts-jest"
  }
}

to this:

module.exports = {
  transform: {
    "^.+\\.(t|j)s$": ['ts-jest', { diagnostics: { ignoreCodes: ['TS151001'] } }],
  }
}

tmdkamins avatar Apr 06 '24 21:04 tmdkamins