Skip to content

ts-jest not reading types from my declaration files #2445

@sslotsky

Description

@sslotsky

🐛 Bug Report

Interfaces defined in my project's .d.ts file are not picked up by ts-jest.

My project uses types defined in plugin/types/interface.d.ts. The source code in plugin/src references these types and compiles without issue. But if these types are referenced within the context of ts-jest, the test suite fails to run with Cannot find name errors.

To Reproduce

The complete test setup can be seen in this draft PR

Steps to reproduce the behavior:

  1. Clone repo: git@github.com:gatsbyjs/gatsby-source-shopify-experimental.git
  2. Checkout branch sslotsky/test-setup
  3. Install dependencies with yarn
  4. Switch into the plugin/ directory
  5. Run yarn test

Expected behavior

The tests should pass, but instead:

 FAIL  test/sample-test.spec.ts
  ● Test suite failed to run

    src/client.ts:3:28 - error TS2304: Cannot find name 'ShopifyPluginOptions'.

    3 const adminUrl = (options: ShopifyPluginOptions) =>
                                 ~~~~~~~~~~~~~~~~~~~~
    src/client.ts:8:39 - error TS2304: Cannot find name 'ShopifyPluginOptions'.

Note that VSCode is able to find the interface in the screenshot below, which tells me that from a TypeScript perspective, my configuration should be ok, because otherwise VSCode shows me lots of type errors if I have those configurations wrong.

image

Link to repo (highly encouraged)

https://github.com/gatsbyjs/gatsby-source-shopify-experimental/pull/73/files

Debug log:

# content of ts-jest.log :
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.5.3"},"message":"creating jest presets not handling JavaScript files","sequence":1,"time":"2021-03-11T16:29:22.994Z"}
{"context":{"allowJs":false,"logLevel":20,"namespace":"jest-preset","package":"ts-jest","version":"26.5.3"},"message":"creating jest presets not handling JavaScript files","sequence":2,"time":"2021-03-11T16:29:23.024Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"26.5.3"},"message":"creating Importer singleton","sequence":3,"time":"2021-03-11T16:29:23.573Z"}
{"context":{"actualVersion":"26.6.3","expectedVersion":">=26 <27","logLevel":20,"namespace":"versions","package":"ts-jest","version":"26.5.3"},"message":"checking version of jest: OK","sequence":4,"time":"2021-03-11T16:29:23.578Z"}
{"context":{"logLevel":20,"namespace":"ts-jest-transformer","package":"ts-jest","version":"26.5.3"},"message":"created new transformer","sequence":5,"time":"2021-03-11T16:29:23.578Z"}
{"context":{"logLevel":30,"namespace":"ts-jest-transformer","package":"ts-jest","version":"26.5.3"},"message":"no matching config-set found, creating a new one","sequence":6,"time":"2021-03-11T16:29:23.579Z"}
{"context":{"config":{"automock":false,"cache":true,"cacheDirectory":"/tmp/jest_rt","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/home/sam/gatsby-source-shopify-graphql-poc/plugin","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"injectGlobals":true,"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"7650e90a1ff57f0cbbb2a111f8134593","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/home/sam/gatsby-source-shopify-graphql-poc/plugin","roots":["/home/sam/gatsby-source-shopify-graphql-poc/plugin"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/","\\.pnp\\.[^\\/]+$"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"backports","package":"ts-jest","version":"26.5.3"},"message":"backporting config","sequence":7,"time":"2021-03-11T16:29:23.579Z"}
{"context":{"jestConfig":{"automock":false,"cache":true,"cacheDirectory":"/tmp/jest_rt","clearMocks":false,"coveragePathIgnorePatterns":["/node_modules/"],"cwd":"/home/sam/gatsby-source-shopify-graphql-poc/plugin","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{"ts-jest":{}},"haste":{"computeSha1":false,"throwOnModuleCollision":false},"injectGlobals":true,"moduleDirectories":["node_modules"],"moduleFileExtensions":["js","json","jsx","ts","tsx","node"],"moduleNameMapper":[],"modulePathIgnorePatterns":[],"name":"7650e90a1ff57f0cbbb2a111f8134593","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/home/sam/gatsby-source-shopify-graphql-poc/plugin","roots":["/home/sam/gatsby-source-shopify-graphql-poc/plugin"],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/jest-environment-node/build/index.js","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":["**/__tests__/**/*.[jt]s?(x)","**/?(*.)+(spec|test).[tj]s?(x)"],"testPathIgnorePatterns":["/node_modules/"],"testRegex":[],"testRunner":"/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/jest-jasmine2/build/index.js","testURL":"http://localhost","timers":"real","transform":[["^.+\\.tsx?$","/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/ts-jest/dist/index.js",{}]],"transformIgnorePatterns":["/node_modules/","\\.pnp\\.[^\\/]+$"],"watchPathIgnorePatterns":[]},"logLevel":20,"namespace":"config","package":"ts-jest","version":"26.5.3"},"message":"normalized jest config","sequence":8,"time":"2021-03-11T16:29:23.580Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","requireResult":{"exists":true,"given":"typescript","path":"/home/sam/gatsby-source-shopify-graphql-poc/plugin/node_modules/typescript/lib/typescript.js"},"version":"26.5.3"},"message":"loaded module typescript","sequence":9,"time":"2021-03-11T16:29:23.580Z"}
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"26.5.3"},"message":"patching typescript","sequence":10,"time":"2021-03-11T16:29:23.580Z"}
{"context":{"actualVersion":"4.2.3","expectedVersion":">=3.8 <5","logLevel":20,"namespace":"versions","package":"ts-jest","version":"26.5.3"},"message":"checking version of typescript: OK","sequence":11,"time":"2021-03-11T16:29:23.580Z"}

envinfo

System:
    OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla)
    Node version: 12.13.0

Npm packages:
    "@types/jest": "^26.0.20",
    "jest": "^26.6.3",
    "ts-jest": "^26.5.3",
    "typescript": "^4.2.3"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions