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

module: esnext triggers the module warning diagnostic #748

Closed
mllustosa opened this issue Sep 21, 2018 · 7 comments · May be fixed by procrafts/kata-diamond#20, procrafts/kata-diamond#21 or procrafts/kata-diamond#22
Assignees
Labels
Milestone

Comments

@mllustosa
Copy link

Issue :

Running my tests on version 23.10.1 outputs an error message. Version 23.10.0 works properly.

Expected behavior :

Tests should run without any issue. Even a project with a single dummy expect(1 + 1).toBe(2) doesn't work.

Debug log :

log file content
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.1"},"message":"creating Importer singleton","sequence":1,"time":"2018-09-21T12:09:41.888Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"23.10.1"},"message":"creating jest presets not handling JavaScript files","sequence":2,"time":"2018-09-21T12:09:41.892Z"}
{"context":{"actualVersion":"23.6.0","expectedVersion":">=22 <24","logLevel":20,"namespace":"versions","package":"ts-jest","version":"23.10.1"},"message":"checking version of jest: OK","sequence":3,"time":"2018-09-21T12:09:41.895Z"}
{"context":{"baseOptions":{},"logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.1"},"message":"created new transformer","sequence":4,"time":"2018-09-21T12:09:41.895Z"}
{"context":{"fileName":"/projectURL/src/index.spec.ts","logLevel":20,"namespace":"jest-transformer","package":"ts-jest","transformOptions":{"instrument":false,"rootDir":"/projectURL"},"transformerId":1,"version":"23.10.1"},"message":"computing cache key for /projectURL/src/index.spec.ts","sequence":5,"time":"2018-09-21T12:09:41.896Z"}
{"context":{"logLevel":30,"namespace":"jest-transformer","package":"ts-jest","transformerId":1,"version":"23.10.1"},"message":"no matching config-set found, creating a new one","sequence":6,"time":"2018-09-21T12:09:41.896Z"}
{"context":{"config":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/var/folders/nb/m260xrh97r71ht8_41q1k5200000gn/T/jest_dx","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/projectURL","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["ts","tsx","js","jsx","json","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"36cf4cff8a211a5cfdd96a9117207b64","prettierPath":"/projectURL/node_modules/prettier/index.js","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/projectURL","roots":["/projectURL"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"jest-environment-jsdom","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","testRunner":"/projectURL/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/projectURL/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","transformerId":1,"version":"23.10.1"},"message":"backporting config","sequence":7,"time":"2018-09-21T12:09:41.897Z"}
{"context":{"jestConfig":{"automock":false,"browser":false,"cache":true,"cacheDirectory":"/var/folders/nb/m260xrh97r71ht8_41q1k5200000gn/T/jest_dx","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/projectURL","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"filter":null,"forceCoverageMatch":[],"globals":{"ts-jest":{}},"haste":{"providesModuleNodeModules":[]},"moduleDirectories":["node_modules"],"moduleFileExtensions":["ts","tsx","js","jsx","json","node"],"moduleNameMapper":{},"modulePathIgnorePatterns":[],"name":"36cf4cff8a211a5cfdd96a9117207b64","prettierPath":"/projectURL/node_modules/prettier/index.js","resetMocks":false,"resetModules":false,"resolver":null,"restoreMocks":false,"rootDir":"/projectURL","roots":["/projectURL"],"runner":"jest-runner","setupFiles":[],"setupTestFrameworkScriptFile":null,"skipFilter":false,"snapshotSerializers":[],"testEnvironment":"jest-environment-jsdom","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":["/node_modules/"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","testRunner":"/projectURL/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/projectURL/node_modules/ts-jest/dist/index.js"]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"23.10.1"},"message":"normalized jest config","sequence":8,"time":"2018-09-21T12:09:41.897Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsJestConfig":{"compiler":"typescript","diagnostics":{"ignoreCodes":[6059,18002,18003],"pretty":true,"throws":true},"isolatedModules":false,"transformers":[],"tsConfig":{"kind":"file"}},"version":"23.10.1"},"message":"normalized ts-jest config","sequence":9,"time":"2018-09-21T12:09:41.898Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"version":"23.10.1"},"message":"babel is disabled","sequence":10,"time":"2018-09-21T12:09:41.899Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.1"},"message":"loaded module typescript","sequence":11,"time":"2018-09-21T12:09:42.097Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"23.10.1"},"message":"patching typescript","sequence":12,"time":"2018-09-21T12:09:42.097Z"}
{"context":{"actualVersion":"3.0.3","expectedVersion":">=2.7 <4","logLevel":20,"namespace":"versions","package":"ts-jest","version":"23.10.1"},"message":"checking version of typescript: OK","sequence":13,"time":"2018-09-21T12:09:42.098Z"}
{"context":{"logLevel":20,"namespace":"config","package":"ts-jest","transformerId":1,"tsConfigFileName":"/projectURL/tsconfig.json","version":"23.10.1"},"message":"readTsConfig(): reading /projectURL/tsconfig.json","sequence":14,"time":"2018-09-21T12:09:42.098Z"}
{"context":{"diagnosticCodes":[151001],"diagnosticText":"\u001b[93mwarning\u001b[0m\u001b[90m TS151001: \u001b[0mIf 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.\n","logLevel":20,"namespace":"TSError","package":"ts-jest","version":"23.10.1"},"message":"created new TSError","sequence":15,"time":"2018-09-21T12:09:42.131Z"}

Output :

image

Minimal repo :

Clone repo bellow and try running npm test.
https://github.com/mllustosa/ts-jest-issue

@huafu huafu self-assigned this Sep 21, 2018
@huafu huafu added this to the 23.10.2 milestone Sep 21, 2018
@huafu huafu added the 🐛 Bug label Sep 21, 2018
@huafu huafu changed the title Tests fail to run on version 23.10.1 module: esnext triggers the module warning diagnostic Sep 21, 2018
@huafu
Copy link
Collaborator

huafu commented Sep 21, 2018

thanks @mllustosa, this is due to the use of esnext value for module in tsconfig. But yeah, it's a bug and should not trigger the diagnostic.

You can put this in your jest config to silent the issue while the fix get ready (this is explained in the documentation):

// jest.config.js
{
  // ...
  globals: {
    'ts-jest': {
      // ...
      diagnostics: {
        ignoreCodes: [151001]
      }
    }
  }
}

@mllustosa
Copy link
Author

You are great, man! thanks for the extremely fast reaction and for linking to the documentation. I've set warnOnly for now.

huafu added a commit to huafu/ts-jest that referenced this issue Sep 22, 2018
Diagnostics have a category. By default if warnOnly is not set, when
diagnostic(s) of kind message or suggestion will be raised, ts-jest will
log it but not throw. This also changes the category of the internal
TS151000.

Closes kulshekhar#748
owennw added a commit to owennw/container-service that referenced this issue Nov 5, 2018
The module value in tsconfig is like `esnext` and erroneously triggers a diagnostic warning, as
shown in this issue: kulshekhar/ts-jest#748
BastianBlokland added a commit to BastianBlokland/typedtree-editor that referenced this issue Jan 23, 2019
@bbugh
Copy link

bbugh commented Apr 7, 2019

This is happening for me since going through an upgrade. The tests run fine, tsc runs fine, but I get this warning for all of my tests.

Disabling the diagnostic as demonstrated in this thread works, but I'm hesitant to disable a warning if there is a reason that warning is happening. Is this something that should still be fixed by ts-jest, or is there something else to do in our code? The warning isn't very clear on what the problem is.

@alexbjorlig
Copy link

To save any Angular developers stuck with this issue, if you are using jest-preset-angular, remember to read this section in the readme about having a custom ts-config globals setup. I hope this can save you some time debugging failing tests 🤓

@giggio
Copy link

giggio commented Jul 11, 2019

I believe this will become more of a problem now that the recently released Angular 8 defaults to esnext.

Is this going to become a problem? @huafu mentions on #753 that:

FYI we must enforce commonjs module as Jest relies on it.

leafac added a commit to leafac/yocto-cfa that referenced this issue Jul 26, 2019
wimpyprogrammer added a commit to wimpyprogrammer/regex-to-strings that referenced this issue Sep 8, 2019
Install ts-jest to support Jest tests that use and import TypeScript.

Pin to ts-jest 23.10.0 to avoid kulshekhar/ts-jest#748.
@aymkin
Copy link

aymkin commented Jun 6, 2021

just set properly tsconfig.ts

{
  "compilerOptions": {
    "esModuleInterop": true,
  }
}

@lbragile
Copy link

Make sure your tsconfig.json is visible from your jest.config.js (if not in root - near package.json):

// config/jest.config.js (same folder as config/tsconfig.json)
...
module.exports = {
  rootDir: "../",
  preset: "ts-jest",
  globals: {
    "ts-jest": {
      compiler: "typescript",
      tsConfig: "config/tsconfig.json", // ← important !!!
      babelConfig: "config/.babelrc.json"
    }
  },
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment